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. Struts2核心包

    Commons-logging.jar  --------------   用于通用日志处理 Freemarker.jar  --------------   表现层框架,定义了struts2的可视组 ...

  2. C#获得命令提示符输出

    原文:http://blog.csdn.net/abrahu/article/details/6611504 C#获得命令提示符输出 分类: c#应用程序2011-07-16 23:34 600人阅读 ...

  3. MAC上使用maven打android的包,报错:No Android SDK path could be found. 解决办法

    对android工程运行mvn compile出现如下信息: No Android SDK path could be found. You may configure it in the pom u ...

  4. getchar()与EOF

    大师级经典的著作,要字斟句酌的去读,去理解.以前在看K&R的The C Programming Language(Second Edition)中第1.5节的字符输入/输出,很迷惑getcha ...

  5. c#读取xml文件配置文件Winform及WebForm-Demo具体解释

    我这里用Winform和WebForm两种为例说明怎样操作xml文档来作为配置文件进行读取操作. 1.新建一个类,命名为"SystemConfig.cs".代码例如以下: < ...

  6. Python文件或目录操作的常用函数

    ◆ os.listdir(path) Return a list containing the names of the entries in the directory given by path. ...

  7. 一步一步学c#(四):继承

    继承 1·继承的类型 在面向对象的编程中,有两种截然不同的继承类型,实现继承和接口继承. 实现继承:表示一个类型派生于一个基类型,它拥有该基类型的所有成员字段和函数. 接口继承:表示一个类型只继承了函 ...

  8. python 整数和浮点数

    整数和浮点数 Python支持对整数和浮点数直接进行四则混合运算,运算规则和数学上的四则运算规则完全一致. 基本的运算: 1 + 2 + 3 # ==> 6 4 * 5 - 6 # ==> ...

  9. GridView中日期显示格式

    DataFormatString="{0:d}"

  10. jquery数字验证大小比较

    $("#rewardForm").validate({            rules: {                "reward": {       ...