js压缩工具jsmin--nodejs常用模块(2)
2014-06-01 23:38
369 查看
简单介绍
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也是这样的
相关文章推荐
- node.js常用模块
- Node.JS核心模块之全局对象和常用工具
- node.js常用模块
- node.js常用的几个模块总结
- Node.js 核心库/常用模块
- Node.js Buffer 模块常用的方法
- js压缩工具uglify-js--nodejs常用模块(3)
- Node.js常用工具之util模块
- NODE.JS加密模块CRYPTO常用方法介绍
- nodejs express 常用模块之config-lite
- Node.js中process模块常用的属性和方法
- node.js学习笔记之常用模块介绍
- node.js加密模块crypto常用方法介绍
- node.js常用模块
- 兼容AMD,nodejs/commonjs规范的模块定义
- golang与node.js的http模块性能对比测试(go1)
- golang与node.js的http模块性能对比测试(go1)
- 深入浅出Node.js(三):深入Node.js的模块机制
- Node.js爬虫--网页请求模块