用quote_keys缩小JavaScript是行不通的



我正在使用gulp缩小javascript。

我的JS有如下对象

var a={"v":5}

但是缩小后它将我的对象转换为以下内容:

var a={v:5}// but I don't want it to remove quotes in keys

因为我在chrome扩展中使用了这个javascript(基本上我想删除这个错误)

我的吞咽任务如下:

var uglify = require('gulp-uglify');
gulp.task('build1',function() {
    gulp.src(['../ext/app/background.js']).on('error', function(e){
        console.log("error:",e)
    }).pipe(uglify({mangle:true,quote_keys:true})).on('error', function(e){
        console.log("error1:",e)
    }).pipe(gulp.dest('../ext/app'));
});

这是因为您在使用 gulp-uglify 包时将quote_keys作为选项传递,而不是将其包含在 gulpfile output选项中。试试这个,你会得到想要的输出。

 gulp.task('build1',function() {
    gulp.src(['a.js']).on('error', function(e){
        console.log("error:",e)
    }).pipe(uglify({output:{quote_keys:true}})).on('error', function(e){
        console.log("error1:",e)
    }).pipe(gulp.dest('app'));
   });

最新更新