导航:首页 > 编程语言 > 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使用相关的资料

热点内容
id为什么下载不得app 浏览:658
打印机扫描的文件路径怎么修改 浏览:876
编程在哪里做兼职 浏览:804
为什么总是复制隐藏文件 浏览:203
稳捷网络 浏览:908
网页打印保存pdf文件怎么打开 浏览:150
编译文件路径不能包含空格 浏览:44
linux打开文件系统检查失败 浏览:624
用什么网站能接室内翻新的活 浏览:235
三星手机应用程序许可 浏览:203
mh版本 浏览:288
编程猫幼儿园怎么样 浏览:50
公交app如何安装 浏览:692
iphone4耳机怎么用 浏览:605
学习课文的app有哪些 浏览:834
ios10导出文件到电脑 浏览:9
数控编程怎么编新程序 浏览:418
编程题怎么分解 浏览:998
本科生找工作应该学什么编程语言 浏览:803
android系统应用升级 浏览:55

友情链接