uglifyjs API问题:无效的映射

时间:2019-05-10 12:54:07

标签: javascript uglifyjs2

下面是我使用uglify js的js压缩代码。 当我在压缩中添加global_defs以将警报转换为console.log时,会创建一个问题,否则,它将正常工作。它给出了类似下面的错误

enter image description here     var UglifyJS = require(“ uglify-js”);     var fs = require('fs');

var code = {
    "file1.js": "/** @preserve Foo Bar */ alert(HelloWorld); function add(first, second) { return first + second; }",
    "file2.js": "console.log(add(1 + 2, 3 + 4));"
};

var option ={
    parse: {
        // parse options
    },
    compress: {
        // compress options
        global_defs: {
            "@alert": "console.log"
        }
    },
    mangle: {
        // mangle options
        reserved: ['first'],
        //toplevel: true,
        properties: {
            // mangle property options
        }
    },
    output: {
        // output options
        comments: "some",
    },
    sourceMap: {
        // source map options
        root: "http://example.com/src",
        filename: "out.js",
        url: "out.js.map",
    },
    nameCache: null, // or specify a name cache object
    toplevel: false,
    ie8: false,
    warnings: false,
}


var uglify = {
    main: {
            src: ['js/file1.js'],
            dest: 'file1.min.js'
    }
};

var result = UglifyJS.minify(code, option);
console.log(result.map);
console.log(result.error);
console.log(result.code);

fs.writeFileSync('site.min.js', result.code);
enter code here

0 个答案:

没有答案