Javascript 使用 UglifyJS 缩小多个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8812621/
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
Minify multiple files with UglifyJS
提问by jcreamer898
Is it possible to compress multiple files with UglifyJS?
是否可以使用 UglifyJS 压缩多个文件?
Something like...
就像是...
uglifyjs -o app.build.js appfile1.js appfile2.js ...
Also, I am running Uglify via NodeJS in Windows Command Prompt
另外,我在 Windows 命令提示符下通过 NodeJS 运行 Uglify
回答by Jakub
Actually what you want to do (trick it into thinking its just 1 file) is just cat it
实际上你想要做的(欺骗它认为它只有 1 个文件)只是 cat it
Linux
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
回答by jcreamer898
For future readers of this question, w/ UglifyJS2, this is trivial now...
对于这个问题的未来读者,使用 UglifyJS2,这现在是微不足道的......
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
回答by gcb
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.
如果您有十几个作为单独模块的文件。你不能同时丑化他们。这是可取的,因为您可以节省每次启动 nodejs 的构建时间。
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.
yuicompressor 允许这样做,并且不为每个单独的文件启动 jvm 所节省的时间很棒。最后你会得到 file1-min.js、file2-min.js 等等......不是一个串联的 blob。
With uglify you will have to spawn one process per file if you do not want to concatenate output.
使用 uglify,如果您不想连接输出,则必须为每个文件生成一个进程。