Laravel Elixir:如何缩小文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30236411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Elixir: How to minify files?
提问by LuMa
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?
我想使用 Laravel Elixir 来缩小我的 css/files 文件。但我不想使用混合方法并将它们合并。我想要的只是从我原来的“custom.js”生成一个“custom.min.js”文件。有没有办法用 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".
编辑:为了更清楚一点:我最大的问题是我在“资源/资产”中有两个文件夹:js 和 css。所以我基本上想缩小那里的所有文件,并将它们缩小到“public/js”和“public/css”中。
回答by Kovah
Quote from the Laravel documentation:
Note: All tasks will assume a development environment, and will exclude minification. For production, use
gulp --production
.
注意:所有任务都将假设一个开发环境,并且不包括缩小。对于生产,请使用
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.
这意味着如果您希望文件被缩小运行,gulp --production
而不仅仅是gulp
. 这是比直接在 gulp 文件中启用压缩更好的做法,并确保您可以在开发应用程序时调试已编译的文件。
If you want them to be placed in public/assets/css
use the path as a second parameter:
如果您希望将它们放置在public/assets/css
使用路径作为第二个参数:
mix.less('app.less', 'public/assets/css');
回答by Kuya A
gulp --production.
吞咽——生产。
Jeffrey way replied on the issue here: https://laracasts.com/discuss/channels/elixir/elixir-doesnt-minify
Jeffrey way 在这里回答了这个问题:https: //laracasts.com/discuss/channels/elixir/elixir-doesnt-minify
Or you can find it on the documentation. Enjoy coding!
或者您可以在文档中找到它。享受编码!
回答by o.v
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:
如果您只想复制.css
文件,而不使用 LESS 或 SASS,并且不想组合文件(即您想要copy()
具有缩小功能的方法),您可以使用组合方法styles()
,通过为每个.css
文件调用它并传递没有数组的文件名字符串,例如:
mix.styles('some.css');
mix.styles('node_modules/bootstrap/dist/css/bootstrap.css', null, './');
Same can be done for .js
files using scripts()
method:
可以.js
使用scripts()
方法对文件执行相同的操作:
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.
然后您可以使用gulp
(不缩小,创建.map
文件)或gulp --production
(创建缩小的文件),如上述帖子所述。
回答by john
Straight from the Laravel/Elixir docs:
直接来自 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