Concatenation and Minification
mix.combine(['src', 'files'], 'destination'); mix.babel(['src', 'files'], destination); mix.minify('src'); mix.minify(['src']);
If used properly, Laravel Mix and webpack should take care of all the necessary module bundling and minification for you.
However, you may have some legacy code or vendor libraries that need to be concatenated and minified. Not a problem.
Consider the following snippet:
mix.combine(['one.js', 'two.js'], 'merged.js');
This will naturally merge
two.js into a single file, called
merged.js. As always, during development, that merged file will remain uncompressed.
However, for production (
export NODE_ENV=production), this command will additionally minify
Combine Files With Babel Compilation
mix.combine() call to
mix.babel(['one.js', 'two.js'], 'merged.js');
Similarly, you may also minify one or more files with the
mix.minify('path/to/file.js'); mix.minify(['this/one.js', 'and/this/one.js']);
There are a few things worth noting here:
- This method will create a companion
*.min.extfile. So minifying
- Once again, the minification will only take place during a production build. (
- There is no need to call
mix.combine(['one.js', 'two.js'], 'merged.js').minify('merged.js');Just stick with the single
mix.combine()call. It'll take care of both.