导航:首页 > 编程语言 > uglifyjs使用

uglifyjs使用

发布时间:2024-04-19 07:52:31

『壹』 如何使用nodejs 的 uglifyjs 压缩js文件

[js压缩]uglifyjs source.js -mc -o target.min.js
以压缩angular.js为例,可以压缩局部变量名,去掉无用的局部变量,空白符等,压缩比例接近80%,效率不错
[user_00@ ~]$ uglifyjs angular.js -mc -o angular.min.js
WARN: Dropping unused function isBoolean [angular.js:416,9]
WARN: Dropping unused function makeMap [angular.js:446,9]
WARN: Dropping unused function size [angular.js:488,9]
WARN: Dropping unused function isLeafNode [angular.js:523,9]
WARN: Dropping unused function argument boundTranscludeFn [angular.js:4682,27]
WARN: Dropping unused function argument rootElement [angular.js:4681,16]
WARN: Dropping unused function argument nodeList [angular.js:4680,17]
WARN: Dropping unused function argument scope [angular.js:4679,22]
WARN: Dropping unused function nodesetLinkingFn [angular.js:4678,9]
WARN: Dropping unused function argument boundTranscludeFn [angular.js:4690,27]
WARN: Dropping unused function argument rootElement [angular.js:4689,16]
WARN: Dropping unused function argument node [angular.js:4688,13]
WARN: Dropping unused function argument scope [angular.js:4687,22]
WARN: Dropping unused function argument nodesetLinkingFn [angular.js:4686,25]
WARN: Dropping unused function directiveLinkingFn [angular.js:4685,9]
WARN: Dropping unused function stripHash [angular.js:5009,9]
WARN: Dropping unused variable NG_SWITCH [angular.js:13857,4]
WARN: Dropping unused variable fns [angular.js:1536,8]
WARN: Dropping unused variable events [angular.js:1536,13]
WARN: Dropping unused function wrongMode [angular.js:3879,13]
WARN: Dropping unused function argument cause [angular.js:4799,31]
WARN: Dropping unused function argument exception [angular.js:4799,20]
WARN: Dropping unused function argument args [angular.js:8165,28]
WARN: Dropping unused function argument args [angular.js:8231,33]
WARN: Dropping unused function argument names [angular.js:9018,32]
WARN: Dropping unused function argument name [angular.js:9030,40]
WARN: Dropping unused variable value [angular.js:9230,14]
WARN: Dropping unused function argument value [angular.js:12475,36]
[user_00@localhost ~]$ ls -lh angular.*
-rw-rw-r-- 1 user_00 user_00 479K Apr 5 01:53 angular.js
-rw-rw-r-- 1 user_00 user_00 79K May 4 16:09 angular.min.js

『贰』 npm安装完uglifyjs怎么对js代码进行混淆

如果你是全局安装的,可以直接在需要混淆文件的目录下,

按住shift键右击鼠标选择在此处打开命令窗口如图

新建test.js开始测试
varUglifyJS=require('uglify-js');

//代码压缩
varresult=UglifyJS.minify("varb=function(){};",{fromString:true});
console.log(" ===========================");
console.log(result);

//文件压缩
result=UglifyJS.minify(["demo.js"]);
console.log(" ===========================");
console.log(result.code);

//多文件压缩,指定sourcemap和网站来源
result=UglifyJS.minify(["main.js","demo.js"],{
outSourceMap:"out.js.map",
sourceRoot:"http://onbook.me",
mangle:true
});
console.log(" ===========================");
console.log(result.code);
console.log(result.map);

http://blog.fens.me/nodejs-uglifyjs2-js/

阅读全文

与uglifyjs使用相关的资料

热点内容
js跳出each循环语句 浏览:145
c把结果输出到文件格式 浏览:596
怎么样将cad文件发到微信上 浏览:835
艺术数据1点2多少 浏览:669
深圳搬家用哪个app比较好 浏览:72
麦格米特plc如何编程 浏览:376
编程在电子竞技中有哪些应用 浏览:914
不平衡数据如何解决 浏览:508
app如何选择是否添加到资源库 浏览:103
在哪里查找某景点的数据 浏览:896
iphone微信病毒代码 浏览:586
天敏网络机顶盒手机app 浏览:54
js的图片渐变 浏览:692
漯河编程培训机构有哪些 浏览:362
如何编程应用软件 浏览:477
手机千牛声音文件路径 浏览:803
access2010的示例数据库 浏览:529
uclinux编译工具 浏览:233
苹果桌面app如何把数字通知改成小红点 浏览:660
哪里得到验光数据 浏览:507

友情链接