相关疑难解决方法(0)

Uglify-js不会破坏变量名称

试图为我的js库准备好的构建环境.根据网络上的评论,UglifyJS似乎是最好的压缩模块之一,在NodeJS下工作.所以这里是建议缩小代码的最佳方法:

var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;

var orig_code = "... JS code here";
var ast = jsp.parse(orig_code); // parse code and get the initial AST
ast = pro.ast_mangle(ast); // get a new AST with mangled names
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
var final_code = pro.gen_code(ast); // compressed code here
Run Code Online (Sandbox Code Playgroud)

如此处所示,pro.ast_mangle(ast)应该修改变量名称,但事实并非如此.我从这个管道中得到的只是javascript代码,没有空格.起初我认为我的代码没有针对压缩进行优化,但后来我尝试使用Google Closure并进行了相当大的压缩(包含变量名称和所有内容).

UglifyJS专家,任何暗示我做错了什么?

更新:

实际代码太大,无法在此处引用,但即使是这样的代码段也不会被破坏:

;(function(window, document, undefined) {

    function o(id) {
        if (typeof id !== …
Run Code Online (Sandbox Code Playgroud)

javascript compression performance minify uglifyjs

17
推荐指数
2
解决办法
3万
查看次数

标签 统计

compression ×1

javascript ×1

minify ×1

performance ×1

uglifyjs ×1