Laravel Elixir: How to minify files? Laravel Elixir: How to minify files? laravel laravel

Laravel Elixir: How to minify files?


Quote from the Laravel documentation:

Note: All tasks will assume a development environment, and will exclude minification. For production, use gulp --production.

This means if you want the files to be minified run gulp --production instead of just gulp. It's a better practise than enabling compression directly in the gulp file and makes sure you can debug your compiled files while developing the application.

If you want them to be placed in public/assets/css use the path as a second parameter:

mix.less('app.less', 'public/assets/css');


gulp --production.

Jeffrey way replied on the issue here: https://laracasts.com/discuss/channels/elixir/elixir-doesnt-minify

Or you can find it on the documentation. Enjoy coding!


If you just want to copy .css files, without using LESS or SASS, and don't want to combine files (i.e. you want something like a copy() method with minification ability) you can use method for combining, styles(), by calling it for every .css file and passing filename string without array, for example:

mix.styles('some.css');mix.styles('node_modules/bootstrap/dist/css/bootstrap.css', null, './');

Same can be done for .js files using scripts() method:

mix.scripts('some.js');mix.scripts('node_modules/bootstrap/dist/js/bootstrap.js', null, './');

And then you can use gulp (doesn't minify, creates .map files) or gulp --production (creates minified files) as mentioned in above posts.