Minify multiple files with UglifyJS

半城伤御伤魂 提交于 2019-12-03 01:39:40

问题


Is it possible to compress multiple files with UglifyJS?

Something like...

uglifyjs -o app.build.js appfile1.js appfile2.js ...

Also, I am running Uglify via NodeJS in Windows Command Prompt


回答1:


Actually what you want to do (trick it into thinking its just 1 file) is just cat it

Linux

cat file1.js file2.js file3.js file4.js | uglifyjs -o files.min.js

Windows (untested)

type file1.js file2.js > uglifyjs -o files.min.js

OR

type file1.js file2.js > merged.files.js
uglifyjs -o merged.files.js



回答2:


For future readers of this question, w/ UglifyJS2, this is trivial now...

uglifyjs file1.js file2.js -o foo.min.js

There is also support for source maps too.

uglifyjs file1.js file2.js -o foo.min.js --source-map foo.min.js.map --source-map-root http://foo.com/src



回答3:


No.

but as other answers states, in it current form, it can concatenate all of them in the same output. Which is not the same as is being asked.

If you have a dozen files that are individual modules. You can not uglify them all at the same time. Which is desirable because you save build time to start nodejs every time.

yuicompressor allows this, and the time saved by not starting up a jvm for each individual file is great. And in the end you do get file1-min.js, file2-min.js, etc... not one concatenated blob.

With uglify you will have to spawn one process per file if you do not want to concatenate output.



来源:https://stackoverflow.com/questions/8812621/minify-multiple-files-with-uglifyjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!