uglifyjs

UglifyJS is a JavaScript parser, minifier, compressor or beautifier toolkit.

uglifyjs是用js写的js压缩工具, 它包含下列一些工具:

  • parser 从js代码生成AST(抽象语法树)
  • code generator 从AST生成js代码
  • compressor 优化AST 压缩代码
  • mangle 局部变量混淆 变为单字母
  • scope analyzer 作用于分析
  • tree walker 允许我们遍历AST语法树的节点 做点有意思的事情
  • tree tranformer 转换语法树

安装

npm install uglify-js //本地安装
npm install -g uglify-js //全局安装 之后 可以在命令行直接调用 uglifyjs

使用

//建议options放后面,可输入多个js文件 在同一全局作用域解析它们
uglifyjs [input files] [options] //若将选项放前面 则需用 -- 分隔一下,输入的js
uglifyjs --compress --mangle -- input.js //查看帮助
uglifyjs -h

更详细的帮助信息

示例

//压缩 混淆 并输出 source-map文件
uglifyjs script.js -o script.min.js -c -m --source-map script.min.js.map script.min.js 包含:
many codes...
//# sourceMappingURL=script.min.js.map //多个js 压缩合并为1个js
uglifyjs f1.js f2.js -o fs.min.js -c -m --source-map fs.min.js.map //美化代码 不压缩成1行
uglifyjs f1.js f2.js -o fsb.min.js -c -m -b //添加序言 --preamble somewords 不能有空格
uglifyjs script.js -o script1.min.js -c -m --source-map script.min.js.map --preamble /*modify_at:2015-06-18*/ //指定source-map-url 然后用http-server在out.min.js所在文件夹,启动httpServer
uglifyjs script.js -o out.min.js -c -m --source-marp out.min.js.map --source-map-url http://localhost:8080/out.min.js.map --preamble /*modify_at:2015-06-18_23:11:10*/ //--source-map-root 指定js源文件的所在路径或url
uglifyjs /home/doe/work/foo/src/js/file1.js \
/home/doe/work/foo/src/js/file2.js \
-o foo.min.js \
--source-map foo.min.js.map \
--source-map-root http://foo.com/src \
-p 5 -c -m

uglifyjs note的更多相关文章

  1. uglifyjs压缩JS的

    一.故事总有其背景 年末将至,很多闲适的时间,于是刷刷微博,接触各种纷杂的信息——美其名曰“学习”.运气不错,遇到了一个新名词,uglifyjs. 据说是用来压缩JS文件的,据说还能优化JS,据说是基 ...

  2. NPM Scripts 2 -- rimraf copyfiles imagemin usemin htmlmin uglifyjs

    NPM Scripts Part 2 Objectives and Outcomes In this exercise you will learn to build a distribution f ...

  3. 三星Note 7停产,原来是吃了流程的亏

    三星Note 7发售两个月即成为全球噩梦,从首炸到传言停产仅仅47天.所谓"屋漏偏逢连天雨",相比华为.小米等品牌对其全球市场的挤压.侵蚀,Galaxy Note 7爆炸事件这场连 ...

  4. 《Note --- Unreal --- MemPro (CONTINUE... ...)》

    Mem pro 是一个主要集成内存泄露检测的工具,其具有自身的源码和GUI,在GUI中利用"Launch" button进行加载自己待检测的application,目前支持的平台为 ...

  5. 《Note --- Unreal 4 --- Sample analyze --- StrategyGame(continue...)》

    ---------------------------------------------------------------------------------------------------- ...

  6. [LeetCode] Ransom Note 赎金条

    
Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 all 
th ...

  7. Beginning Scala study note(9) Scala and Java Interoperability

    1. Translating Java Classes to Scala Classes Example 1: # a class declaration in Java public class B ...

  8. Beginning Scala study note(8) Scala Type System

    1. Unified Type System Scala has a unified type system, enclosed by the type Any at the top of the h ...

  9. Beginning Scala study note(7) Trait

    A trait provides code reusability in Scala by encapsulating method and state and then offing possibi ...

随机推荐

  1. scanf 和cin 的区别

    笔试的时候经常遇到突然string s;cin>>s; 有的时候编译会错误,不知道为什么. 今天在练习枚举类型的时候,也遇到这样一个问题. enum weekday{Monday,Tues ...

  2. python dict traversal

    rs=dict() rs['item1'] = 'item1' rs['item2'] = 'item2' for k,d in rs.items(): print k,d for k in rs.k ...

  3. < meta > 元素 概要

    < meta > 元素 概要 标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他 we ...

  4. codeforces 383C Propagating tree 线段树

    http://codeforces.com/problemset/problem/383/C 题目就是说,  给一棵树,将一个节点的值+val, 那么它的子节点都会-val, 子节点的子节点+val. ...

  5. java 执行linux命令

    原文地址: http://blog.csdn.net/xh16319/article/details/17302947 package scut.cs.cwh; import java.io.Inpu ...

  6. 什么是位、字节、字、KB、MB

    什么是位.字节.字.KB.MB 位:"位(bit)"是电子计算机中最小的数据单位.每一位的状态只能是0或1. 字节:8个二进制位构成1个"字节(Byte)",它 ...

  7. java把函数作为参数传递

    public class Tool { public void a()// /方法a { System.out.print("tool.a()..."); } public voi ...

  8. substr,substring,slice 的区别

    javascript中的三个函数substr,substring,slice都可以用来提取字符串的某一部分(函数名称都是小写,不要写成subStr,subString又或者Substring,记住js ...

  9. Http静态资源的缓存

    最近一段时间一直在研究页面缓存和压缩方面的东西,由于公司服务器使用的是iis6.0,很多性能方面的优化都不支持.所以,就开始尝试着自己写个简单的处理程序. 为了减少服务器带宽的需求,我们要减少客户端与 ...

  10. mongoose的populate的使用方法;

    LotteryReceiveRecord.find({"lottery":req.params.id}).populate("user lottery").ex ...