11

I want to use Laravel Elixir to minify my css/files files. But I don't want to use the mix-methode and merge them. All I want is to generate a "custom.min.js" file from my original "custom.js". Is there a way to do this with Elexir?

EDIT: To make it a bit clearer: My biggest issue is that I have two folders in "resources/assets": js and css. So I basically want to minify all files in there and have them minified in "public/js" and "public/css".

LuMa
  • 1,673
  • 3
  • 19
  • 41

4 Answers4

23

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');
Kevin
  • 1,633
  • 1
  • 22
  • 37
  • 9
    I prefer to have gulp run both at the same time, so you get both dev and production files. Then in my app, based on environment I simply load the appropriate one. This is much better than having to remember to run the minification every time. – Oddman Dec 27 '15 at 15:06
4

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!

Kuya A
  • 351
  • 2
  • 18
1

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.

o.v
  • 835
  • 10
  • 15
0

Straight from the Laravel/Elixir docs:

Elixir is built on top of Gulp, so to run your Elixir tasks you only need to run the gulp command in your terminal. Adding the --production flag to the command will instruct Elixir to minify your CSS and JavaScript files:

Run all tasks... gulp

Run all tasks and minify all CSS and JavaScript... gulp --production

docs: https://laravel.com/docs/5.3/elixir#running-elixir

john
  • 539
  • 5
  • 13