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. OpenCV学习(1)OpenCV简介

    简介 OpenCV的全称是:Open Source Computer Vision Library,OpenCV是一个开源的跨平台的计算机视觉库,可以运行在Linux.Windows和Mac OS操作 ...

  2. mysql--自动增长

    create table teacher( t_id int primary key auto_increment, #auto_increment 自动增长 需要整型,还需要索引 t_name va ...

  3. jquery写的tab切换效果 非常简单

    自己写的一款 tab切换效果,比较简单,适合新手 <style type="text/css">*{margin:0; padding:0; font-size:12p ...

  4. 关于AJAX+HTML5+ASHX进行全静态页面的数据交互

    及时总结项目中使用到的知识,知识在于积累. 1.HTML代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN ...

  5. client|server 最简单的聊天

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sys/socket ...

  6. SQL Server 修改表

    alter table 可能用三种方式来完成. 第一种: 只修改元数据. 1.删除一个列. 2.一个行被增加而且空值被认为是所有行的新值. 3.当可变长度的列的长度增加时. 4.不允许为空的列被允许为 ...

  7. 发送邮件java实现

    下面代码可以实现普通qq邮箱发送邮件的功能,可以传附件,但是是固定的附件: 需要两个jar包:mail.jar,activation.jar mail.jar 下载地址: http://java.su ...

  8. Linux bug 14258279: scheduling clock overflows in 208 days

    早上同事反映数据库不能用.无法正常登录主机.多次尝试后终于登上主机,检查系统日志发现下述错误: BUG: soft lockup - CPU#5 stuck for 17163091988s! 貌似是 ...

  9. Oracle系列:记录Record

    Oracle系列:记录Record   分类: [Oracle] (15) 版权声明:本文为博主原创文章,未经博主允许不得转载. Oracle系列:记录(Record) 一,什么是记录(Record) ...

  10. JSP中的Attribute和InitParameter

    属性:Attribute类型:应用/上下文,请求,会话(ServletContext,HttpServletRequest/ServletRequest,HttpSession)设置方法:setAtt ...