Search code examples
javascriptuglifyjsuglifyjs2

UglifyJS 2: api equivalent for cli -m toplevel?


I'm trying to convert the following command:

uglifyjs src1.js src2.js -c -m toplevel --screw-ie8

to an API call:

ug.minify(['src1.js','src2.js'], {mangle:true, compress:true, ie_proof:false})

But I can't figure out how to set 'toplevel'. Setting toplevel:true or mangle:'toplevel' doesn't work.


Solution

  • Put the toplevel option within object literals:

    require('uglify-js').minify(['src1.js','src2.js'], {
        mangle: {
            toplevel: true
        },
        compress: true,
        ie_proof: false
    });