Home > Software design >  Specify the order of scripts in Laravel Mix
Specify the order of scripts in Laravel Mix

Time:05-13

I'm trying to combine two JS scripts into one file. One is a third-party library, and the other is some custom js. No matter how I specify the scripts in the mix.js array, it always puts the custom.js on top. I want to put the library on top. How can I achieve that?

Method 1

mix.js([
    'node_modules/zoid/dist/zoid.frameworks.frame.min.js',
    'public/js/custom.js'
], 'public/js/combined.js').version();

Method 2

mix.js([
    'public/js/custom.js',
    'node_modules/zoid/dist/zoid.frameworks.frame.min.js'
], 'public/js/combined.js').version();

CodePudding user response:

Consider the following Mix configuration file.

mix.combine(['one.js', 'two.js'], 'merged.js');

This instructs Mix to merge - or concatenate - one.js and two.js into a single file, called merged.js. As always, during development, that merged file will remain uncompressed. However, when building for production, merged.js will, of course, be minified.

Also, mix.scripts() is an alias for mix.combine(); you can use either or.

  • Related