用quote_keys缩小javascript是行不通的

时间:2017-01-26 07:17:10

标签: javascript google-chrome-extension gulp gulp-uglify

我正在使用gulp缩小javascript。

我的JS有像下面这样的对象

var a={"v":5}

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

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

因为我在chrome扩展程序中使用此javascript(基本上我想删除this error

我的gulp任务如下:

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'));
});

1 个答案:

答案 0 :(得分:0)

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

 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'));
   });