Mangle nested classes and variables with uglifyjs

前端 未结 5 1838
礼貌的吻别
礼貌的吻别 2021-01-05 08:26

I use uglifyjs to minify a concatenated set of files, which works fine but not good enough. The built lib uses namespaces, so classes, functions and constants are stored in

5条回答
  •  执笔经年
    2021-01-05 09:15

    When you minimize Javascript you can only change names of variables, the api, core and names are not variables but properties of an object. If these were changed by the minimizer, you would potentially get unexpected results. What if in your code you would call

    root["api"].perform = function()...
    

    or even something like

    function doIt(section, method, argument) {
        root[section][method](argument);
    }
    doIt('api','perform', 101);
    

    All perfectly legal JS, but a minimizer could never figure out what's going on.

提交回复
热议问题