11

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

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

4

4 回答 4

23

引用Laravel 文档

注意:所有任务都将假定一个开发环境,并且不包括缩小。对于生产,使用gulp --production.

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

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

mix.less('app.less', 'public/assets/css');
于 2015-07-30T10:25:28.410 回答
4

吞咽——生产。

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

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

于 2016-06-30T07:53:16.383 回答
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(创建缩小文件),如上面的帖子中所述。

于 2016-12-21T14:39:38.140 回答
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

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

于 2017-02-18T05:50:13.340 回答