简体   繁体   中英

UglifyJS2 , -m sort option does not work

I'm trying to minifier a simple javascript code with UglifyJS2 , but also by including the - m sort in the command, the variables are not changed

Mangler , sort options

sort — to assign shorter names to most frequently used variables. This saves a few hundred bytes on jQuery before gzip, but the output is bigger after gzip (and seems to happen for other libraries I tried it on) therefore it's not enabled by default.

This is the command that I use

uglifyjs jsfile.js -m sort -c -o jsfile.min.js

This is the jsfile.js

var ciao_ciao = 10;

ciao_ciao++;

function ciao_come_va(){


}

ciao_come_va();

This is the jsfile.min.js

function ciao_come_va(){}var ciao_ciao=10;ciao_ciao++,ciao_come_va();

As you can see the name of variables and functions is not changed

Your function and variables will not be mangled because they are in the global scope.

If you wrap your code (as below), the function and variables will be mangled.

(function(){

    var ciao_ciao = 10;

    ciao_ciao++;

    function ciao_come_va(){

    }

    ciao_come_va();

})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM