3

I have 2 different builds for my laravel-mix. Target node and web. Here is what how they look like:

if (process.env.npm_config_section === 'server') {
    mix.js('resources/js/app-server.js', 'public/js')
        .webpackConfig({
            target: 'node',
            plugins: [
                new webpack.optimize.LimitChunkCountPlugin({
                    maxChunks: 1,
                })
            ],
        })
        .mergeManifest()
        .version();
} else if (process.env.npm_config_section === 'client') {
    mix.js('resources/js/app-client.js', 'public/js')
        .webpackConfig({
            target: 'web',
            output: {
                chunkFilename: 'js/chunks/[name].js?id=[chunkhash]',
                publicPath: '/',
            },
        })
        .mergeManifest()
        .version();
}

mix.sass('resources/sass/app.scss', 'public/css')
  • For 'web' - it separates the chunks
  • For 'node' - it only gives 1 file

However, I get an error for 'node' which is fair enough - we don't have window in node target:

return window && document && document.all && !window.atob

ReferenceError: window is not defined

Looking at the compiled file this is where it is crashing which made me think it's style-loader related.

var isOldIE = memoize(function () {
    // Test for IE <= 9 as proposed by Browserhacks
    // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
    // Tests for existence of standard globals is to allow style-loader
    // to operate correctly into non-standard environments
    // @see https://github.com/webpack-contrib/style-loader/issues/177
    return window && document && document.all && !window.atob;
});

What can I do so that 'node' doesn't use style-loader? How can I change this in laravel-mix?

...but to change the style-loader in Laravel-mix based on target?

Community
  • 1
  • 1
senty
  • 12,385
  • 28
  • 130
  • 260

1 Answers1

-1

Not including mix.sass('resources/sass/app.scss', 'public/css') in node target worked :O

senty
  • 12,385
  • 28
  • 130
  • 260
  • That doesn't work. Including or not mix.sass(...), the isOldIE() function is sill in the output JS code and the error keeps showing. – iamalinski Aug 01 '22 at 13:45