简体   繁体   English

如何在同一个browserify命令中缩小和分解文件?

[英]How to minify and factor-bundle files in the same browserify command?

I currently have this factor-bundle command which I use to bundle my files, and pull everything common into a common file: 我目前有这个factor-bundle命令,我用它来捆绑我的文件,并将所有常见的东西拉到一个公共文件中:

browserify index.js bar-charts.js list-filter.js dashboard.js 
  -p [ factor-bundle -o ../../static/js/index.js -o ../../static/js/bar-chart.js -o ../../static/js/list-filter.js -o ../../static/js/dashboard.js ] 
  -o ../../static/js/common.js

I previously also used this command to uglify individual files: 我以前也使用此命令来uglify单个文件:

 browserify index.js | uglifyjs > ../../static/js/index.min.js

How can I both combine files with factor-bundle , and minify them with uglifyjs , in the same command? 我怎样才能将文件与factor-bundle组合factor-bundle ,并在同一个命令中用uglifyjs缩小它们?

I found this example in the factor-bundle docs , but I don't really understand how to adapt it. 在因子包文档中找到了这个例子 ,但我真的不明白如何适应它。

(I could also use two commands, if that works better. I just want to end up with minified and combined files!) (如果效果更好,我也可以使用两个命令。我只想最终得到缩小和组合的文件!)

I happened to have been looking into this area recently and stumbled on what I think might be able to help you. 我最近一直在调查这个区域,偶然发现了我认为可以帮助你的事情。

browserify files/*.js \
    -p [ ../ -o 'uglifyjs -cm | tee bundle/`basename $FILE` | gzip > bundle/`basename $FILE`.gz' ] \
    | uglifyjs -cm | tee bundle/common.js | gzip > bundle/common.js.gz

I've not dabbled much with browserify but to me this looks as though it is simply piping the output from factor-bundle into uglify. 我没有涉及到浏览器,但对我而言,这看起来好像只是将factor-bundle的输出汇总到uglify中。

source: https://gist.github.com/substack/68f8d502be42d5cd4942 来源: https//gist.github.com/substack/68f8d502be42d5cd4942

Hope this helps someone 希望这有助于某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM