0

I'm minifying javascript using gulp.

My JS has objects like following

var a={"v":5}

But after minification it converts my object to following:

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

Because I'm using this javascript in chrome extension (basically I want to remove this error)

My gulp task is as following:

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'));
});
Community
  • 1
  • 1
Akhilesh Kumar
  • 9,085
  • 13
  • 57
  • 95
  • 3
    It's no difference between `{v: 5}` and `{"v": 5}`. Because in first case `v` will be string also. The error by link isnt related to your case. It is about `a[key]` vs `a["key"]` case – Andrey Jan 26 '17 at 08:26

1 Answers1

0

It's because you are passing the quote_keys as an option instead of enclosing it in output option in the gulpfile while using the gulp-uglify package. Try this and you will get the desired 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'));
   });
acesmndr
  • 8,137
  • 3
  • 23
  • 28