简单介绍
- jsmin的实现有很多版本,有C语言、PHP语言的,主流的是C语言写的那个版本。但作为js程序员自然要用js语言版本的。
- 它只是实现了去注释、去空格的压缩,没有实现混淆压缩。
- 写个demo试了下,jsmin也可以对css进行压缩,但网上的同学都没有指出jsmin可以压缩css(不确定再某些情况是不是也能正常压缩)。所以不用它压缩css为好。
帮助文档
https://github.com/pkrumins/node-jsmin
demo
这里只贴了代码,具体步骤参考《js,css压缩工具yuicompressor--nodejs常用模块(1)》。
var jsmin = require('jsmin').jsmin;
var fs = require('fs');
fs.readFile('../source/test.js', 'utf8', function (err, data) {
if (err) {
throw err;
}
fs.writeFile('../source/test_jsmin.js', jsmin(data), function(){
console.log('jsmin success!');
});
});
参数说明
The 'jsmin' function takes three arguments:
* input js code
* integer aggressiveness level (defaults to 2)
* optional comment to prepend to output (defaults to nothing)
The aggressiveness level can be 1, 2 or 3:
* 1 - keep original newlines in output
* 2 - original Crockford's algorithm - remove some newlines
* 3 - remove all newlines
Start the comments that you don't want to remove (as process of minification)
with /! ... / uglify,yuicompressor也是这样的