简体   繁体   English

用于缩小/缩小并将整个项目合并到一个文件的简单工具?

[英]Simple tool for minify/uglify and merge entire project to one single file?

Im looking for a while for a tool that will be able to run on a base folder and merge all javscript files to a single minified file. 我正在寻找一种能够在基本文件夹上运行并将所有javscript文件合并为单个压缩文件的工具。 I looked at uglifyjs2 which seems to be the favorite, but doesnt handle require calls: I tried using the command line compress method on several files, but require calls will remain and will break the code on runtime if I try to run it separately uglifyjs routes/* libs/* config/* models/* server.js -o server.min.js -c sequences,dead_code,booleans,conditionals,properties,unused,if_return,join_vars,hoist_vars 我看了看uglifyjs2,它似乎是最喜欢的,但不能处理require调用:我尝试对多个文件使用命令行compress方法,但是如果我尝试单独运行uglifyjs routes/* libs/* config/* models/* server.js -o server.min.js -c sequences,dead_code,booleans,conditionals,properties,unused,if_return,join_vars,hoist_vars ,则要求调用将保留下来,并且会在运行时破坏代码。 uglifyjs routes/* libs/* config/* models/* server.js -o server.min.js -c sequences,dead_code,booleans,conditionals,properties,unused,if_return,join_vars,hoist_vars

So I cant really make the "single" file version, only to uglify and generate a minified version for each file, but the entire project structure remains. 因此,我无法真正制作“单个”文件版本,只是为了使每个文件丑化并生成一个缩小的版本,但是整个项目结构仍然存在。 I also tried to experience with node-optimize, but it will leave many trails in the code, with __FAKE_REQUIRE__ declarations holding the full path for my files, even though it was initially relative only (being a full path, its not portable to other computers) 我也尝试过节点优化,但是它将在代码中留下很多痕迹, __FAKE_REQUIRE__声明保留了我文件的完整路径,即使它最初只是相对的(是完整路径,也无法移植到其他计算机上) )

Is there a reasonable way to generate a single file with the content of the entire project and then to uglify it, having a good and easy (single file) distribution release? 有没有一种合理的方法来生成包含整个项目内容的单个文件,然后对其进行丑化处理,从而发布一个既好又简单的(单个文件)发行版本?

You can use Grunt for this purpose. 您可以为此使用Grunt。 For this, first of all you can specify in it that what your sources are. 为此,首先您可以在其中指定来源。 After that you can concat on them and then uglify/minify to get a single file. 之后,您可以合并它们,然后进行丑化/缩小以获得单个文件。 Please check this resource http://gruntjs.com/getting-started 请检查此资源http://gruntjs.com/getting-started

I would recommend a mix of browserify and Google Closure Compiler 我建议同时使用browserifyGoogle Closure Compiler

With browserify you can keep your source code nicely separated while developing ("requiring" files in CommonJS format) and then generate a single "bundle" file when moving into production. 使用browserify,您可以在开发过程中很好地分离源代码(CommonJS格式的“要求”文件),然后在投入生产时生成单个“捆绑”文件。 Then you can minify that single file (and others if you wish, including 3rd party libraries) with Closure Compiler (or even with uglifyjs). 然后,您可以使用Closure Compiler(甚至使用uglifyjs)最小化单个文件(如果需要,还可以压缩其他文件,包括第三方库)。

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

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