【问题标题】:minifying javascript with quote_keys is not working使用 quote_keys 缩小 javascript 不起作用
【发布时间】:2017-01-26 07:17:09
【问题描述】:

我正在使用 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'));
});

【问题讨论】:

  • {v: 5}{"v": 5} 没有区别。因为在第一种情况下 v 也将是字符串。链接错误与您的情况无关。这是关于a[key]a["key"] 案例

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


【解决方案1】:

这是因为您在使用 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'));
   });

【讨论】:

    猜你喜欢
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 2018-11-30
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多