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')); }); 
1
  • 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 Commented Jan 26, 2017 at 8:26

1 Answer 1

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')); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.