We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
The community reviewed whether to reopen this question 3 years ago and left it closed:
Original close reason(s) were not resolved
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(9)
我建议使用 UglifyJS,它是 NodeJS 的 JavaScript 解析器/管理器/压缩器/美化器库。
如果您对不仅仅只是连接和缩小文件的自动化工具感兴趣,可以使用以下解决方案:
GruntJS 是一个用于 JavaScript 项目的基于任务的命令行构建工具。当前版本有以下内置任务:
除了这些任务之外,还有很多可用的插件。
Gulp 是一个工具包,可帮助您自动执行开发工作流程中痛苦或耗时的任务。对于 Web 开发(如果您喜欢的话),它可以通过执行 CSS 预处理、JS 转译、缩小、实时重新加载等来帮助您。所有主要 IDE 中都内置了集成,人们喜欢跨 PHP、.NET、Node.js、Java 等。 gulp 拥有超过 1700 个插件(还有很多不需要插件的功能),让您不再搞乱构建系统并重新开始工作。
Yeoman 是一组强大且固执己见的工具、库和工作流程,可以帮助开发人员快速构建美观、引人注目的网络应用程序。
I recommend using UglifyJS which is a JavaScript parser / mangler / compressor / beautifier library for NodeJS.
If you are interested in automation tools that do more than simply concatenate and minify files, there are the following solutions:
GruntJS is a task-based command line build tool for JavaScript projects. The current version has the following built-in tasks:
Besides this tasks there's a lot of plugins available.
Gulp is a toolkit that will help you automate painful or time-consuming tasks in your development workflow. For web development (if that's your thing) it can help you by doing CSS preprocessing, JS transpiling, minification, live reloading, and much more. Integrations are built into all major IDEs and people are loving gulp across PHP, .NET, Node.js, Java, and more. With over 1700 plugins (and plenty you can do without plugins), gulp let's you quit messing with build systems and get back to work.
Yeoman is a robust and opinionated set of tools, libraries, and a workflow that can help developers quickly build beautiful, compelling web apps.
UglifyJS 是一个 Node 模块,主要用于缩小 JavaScript。我不认为它也可以连接文件,但我可能错过了一个选项。
编辑:
在 UglifyJS 2 中,它也内置了串联。
如果您想在节点应用程序中内联执行此操作,那非常简单。这允许您在运行时动态生成缩小/连接的 js 脚本,而无需使用 grunt 或 yeoman 方式。
在你的模块中:
UglifyJS is a Node module that is all about minifying javascript. I don't think it also joins files, but there might be an option I missed.
Edit:
With UglifyJS 2, it has built in concatenation as well.
If you want to do this inline in your node app it's really easy. This allows you to dynamically generate your minified/concatenated js script at runtime without using the grunt or yeoman way.
and in your module:
如果您使用 Connect,那么我很幸运 Connect-Assetmanager
If you're using Connect, then I've had good luck with Connect-Assetmanager
您最好使用 gulp / webpack 之类的东西来连接/组织/捆绑您的资产。
为了加入 js 文件,你可以像 twitter bootstrap makefile 中那样做,
这只是文件的串联,并输出到 js 文件
然后你可以安装 uglify-js 来缩小 js:
并使用你的路径/文件执行此命令.js ofc:
正如 uglifyjs 2 以来的评论中提到的,你也可以这样做:
You'll be better using something like gulp / webpack to concat/organize/bundle your assets.
In order to join js file you can do as its done in twitter bootstrap makefile
This is just a concatenation of files with an output to a js file
Then you can install uglify-js to minify js:
And perform this command with your path/file.js ofc:
As mentioned in comments since uglifyjs 2 you could also do:
如果您喜欢 Rails 3.1 资产管道方法,您应该尝试我的 connect-assets 库。
If you like the Rails 3.1 asset pipeline approach, you should try my connect-assets library.
我绝对推荐闭包编译器的简单模式。
I'd definitely suggest the Closure Compiler's simple mode.
也许不完全是你正在寻找的东西,但 Enderjs 可以工作。
Maybe not exactly what you're looking for but Enderjs could work.
尝试这两个 Grunt 插件
https://www.npmjs.org/package/grunt-contrib -concat
https://www.npmjs.org/package/grunt-contrib-uglify
你可以像这样安装你需要的一切:
然后创建你的 grunt 文件,像这样:
Gruntfile.js
最后,在终端中输入
grunt
,Grunt 将开始监视 JavaScript 文件的更改,并自动连接和丑化它们(每当您将更改保存到 ../src/ 中的 js 文件时)Try these two plugins for Grunt
https://www.npmjs.org/package/grunt-contrib-concat
https://www.npmjs.org/package/grunt-contrib-uglify
You can install everything you need like so:
Then create your grunt file, like so:
Gruntfile.js
Finally, type
grunt
in the terminal and Grunt will start watching your JavaScript files for changes and automatically concat and uglify them (whenever you save a change to your js files in ../src/如果您已经有
uglify-js
,您的代码将使用一些最新的 ES6 功能 (ECMAScript 2015 ) 并且它只是在第一次运行时返回解析错误,然后安装 uglify-es:或者:
解释在 uglify-js-es6 包:
您仍然可以使用
uglifyjs
命令正常运行它。压缩和重整示例:这将生成一个包含文件夹中所有 JS 文件的文件。双破折号 (
--
) 只是防止输入文件用作选项参数。If you already have
uglify-js
, your code uses some of the latest ES6 features (ECMAScript 2015) and it just gave you back parse errors on the first run, then install uglify-es:Or:
The explanation is in uglify-js-es6 package:
You can still run it normally with the
uglifyjs
command. A compress and mangle example:Which will produce a single file with all the JS files of a folder. The double dash (
--
) just prevents input files being used as option arguments.