Laravel Elixir:如何缩小文件?

时间:2015-05-14 11:37:35

标签: laravel laravel-5 gulp laravel-elixir

我想使用Laravel Elixir来缩小我的css / files文件。但我不想使用mix-method并合并它们。我想要的是从我原来的“custom.js”生成一个“custom.min.js”文件。有没有办法用Elexir做到这一点?

编辑: 为了使它更清楚:我最大的问题是我在“资源/资产”中有两个文件夹:js和css。所以我基本上想要缩小其中的所有文件,并将它们缩小为“public / js”和“public / css”。

4 个答案:

答案 0 :(得分:22)

来自Laravel documentation

的引用
  

注意:所有任务都将采用开发环境,并且不包括缩小。对于制作,请使用gulp --production

这意味着如果您希望缩小文件,请运行gulp --production而不是gulp。这比在gulp文件中直接启用压缩更好,并确保您可以在开发应用程序时调试编译的文件。

如果您希望将它们放在public/assets/css中,请将路径用作第二个参数:

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

答案 1 :(得分:4)

gulp --production。

Jeffrey Way在这里回答了这个问题:https://laracasts.com/discuss/channels/elixir/elixir-doesnt-minify

或者您可以在文档中找到它。享受编码!

答案 2 :(得分:1)

如果您只想复制.css文件,而不使用LESS或SASS,并且不想合并文件(即您想要具有缩小功能的copy()方法),您可以使用组合styles()的方法,通过为每个.css文件调用它并传递没有数组的文件名字符串,例如:

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

使用.js方法可以对scripts()个文件执行相同操作:

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

然后您可以使用gulp(不缩小,创建.map文件)或gulp --production(创建缩小文件),如上文所述。

答案 3 :(得分:0)

直接来自Laravel / Elixir文档:

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