uglifyjs note
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的更多相关文章
- uglifyjs压缩JS的
一.故事总有其背景 年末将至,很多闲适的时间,于是刷刷微博,接触各种纷杂的信息——美其名曰“学习”.运气不错,遇到了一个新名词,uglifyjs. 据说是用来压缩JS文件的,据说还能优化JS,据说是基 ...
- 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 ...
- 三星Note 7停产,原来是吃了流程的亏
三星Note 7发售两个月即成为全球噩梦,从首炸到传言停产仅仅47天.所谓"屋漏偏逢连天雨",相比华为.小米等品牌对其全球市场的挤压.侵蚀,Galaxy Note 7爆炸事件这场连 ...
- 《Note --- Unreal --- MemPro (CONTINUE... ...)》
Mem pro 是一个主要集成内存泄露检测的工具,其具有自身的源码和GUI,在GUI中利用"Launch" button进行加载自己待检测的application,目前支持的平台为 ...
- 《Note --- Unreal 4 --- Sample analyze --- StrategyGame(continue...)》
---------------------------------------------------------------------------------------------------- ...
- [LeetCode] Ransom Note 赎金条
Given an arbitrary ransom note string and another string containing letters from all th ...
- 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 ...
- 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 ...
- Beginning Scala study note(7) Trait
A trait provides code reusability in Scala by encapsulating method and state and then offing possibi ...
随机推荐
- BZOJ 1396: 识别子串( 后缀数组 + 线段树 )
这道题各位大神好像都是用后缀自动机做的?.....蒟蒻就秀秀智商写一写后缀数组解法..... 求出Height数组后, 我们枚举每一位当做子串的开头. 如上图(x, y是height值), Heigh ...
- 编写程序输入一个5x5的矩阵,将最大元素与中心元素交换,并按行列对齐输出。
编写程序输入一个5x5的矩阵,将最大元素与中心元素交换,并按行列对齐输出. 题目描述 编写程序输入一个5x5的矩阵,将最大元素与中心元素交换,并按行列对齐输出. 输入描述 编写程序输入一个5x5的矩阵 ...
- 纯CSS 贴底部的布局(兼容各个浏览器包括IE6)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- nginx 目录密码保护的设置方法
在 nginx.conf 文件中对应的 server 段中 添加 location ^~ /test/ { auth_basic TEST-Login; auth_basic_user_file /r ...
- Allegro的优点与缺点
记得刚毕业出来时就在某台商工作,用的就是allegro,从此上了贼船就下不来了--.其实还用过pcad,protel,powerpcb(以下简称3p,加上pads就4p了,呵呵--).至于mentor ...
- N沟道和P沟道MOS FET开关电路
在电路中常见到使用MOS FET场效应管作为开关管使用.下面举例进行说明. 如图1所示,使用了P沟道的内置二极管的电路,此处二极管的主要作用是续流作用,电路是Li电池充放电电路,当外部电源断开时采用L ...
- Windows 7妙用 笔记本变无线AP轻松共享
笔记本变AP的前提和应用原理 笔记本变AP的前提是你所处的房间或地点需要提供有线宽带的连接,而且你的笔记本要有无线网卡.如果这两个条件具备了,即使没有路由器/无线AP等辅助设备,多个笔记本电脑共享上网 ...
- 从零开始学 iOS 开发的15条建议
事情困难是事实,再困难的事还是要每天努力去做是更大的事实. 因为我是一路自学过来的,并且公认没什么天赋的前提下,进步得不算太慢,所以有很多打算从零开始的朋友会问我,该怎么学iOS开发.跟粉丝群的朋友交 ...
- Windows Azure Web Role 的 IIS 重置
如果您是一名 Web开发人员,您很可能使用过"简单快捷"的iisreset命令重置运行不正常的 IIS主机.这种方法通常在经典的 Windows Server VM上非常有效 ...
- poj1543---完美立方(枚举)
#include <stdio.h> #include <stdlib.h> int main() { int cube[101],n,i,a,b,c,d; for(i=1;i ...