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 ...
随机推荐
- OC中对象元素的引用计数 自动释放池的相关概念
OC中数组对象在是如何处理对象元素的引用计数问题的,同时介绍一下自动释放池的相关概念 一.数组对象是如何处理对象元素的引用计数问题[objc] view plaincopy 1. // 2. / ...
- Python核心编程读笔 13:执行环境
第14章 执行环境 一.可调用对象 python有四种可调用对象:函数.方法.类.一些类的实例 1 函数 (1)内建函数(BIF) BIF是用c/c++写的,编译后放入python解释器,然后把它们 ...
- 微博发布效果jq版
大家都看过新浪微博的发状态功能,我模拟了一下类似的效果,包括发布时间,删除效果等.代码如下: <!DOCTYPE HTML> <html> <head> <m ...
- getElementByID、getElementsByName、getElementsByTagName实例详解
getElementByID.getElementsByName.getElementsByTagName实例详解 本文通过实例,详细介绍了getElementByID.getElementsByNa ...
- MYSQL 用户
MYSQL 并没有与SQL Server一样的两个级别的主体,它只有user. user 的信息都保存在mysql 数据库的 user 表中:我想也可以用insert 的方式新建用户,只是这种尝试还没 ...
- Nginx模块开发入门(转)
前言 Nginx是当前最流行的HTTP Server之一,根据W3Techs的统计,目前世界排名(根据Alexa)前100万的网站中,Nginx的占有率为6.8%.与Apache相比,Nginx在高并 ...
- golang仿AS3写的ByteArray
用golang写了个仿AS3写的ByteArray,稍微有点差别,demo能成功运行,还未进行其他测试 主要参考的是golang自带库里的Buffer,结合了binary 来看看demo: packa ...
- poj2389---大数乘法
#include<stdlib.h> #include<stdio.h> #include<string.h> #define MAX 100 int main() ...
- Spring mvc 简单异常配置jsp页面
原文出处:http://howtodoinjava.com/spring/spring-mvc/spring-mvc-simplemappingexceptionresolver-example/ 这 ...
- 链表-Reverse Linked List
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * } ...