用 quote_keys 缩小 javascript 无效
minifying javascript with quote_keys is not working
我正在使用 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'));
});
这是因为您在使用 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'));
});
我正在使用 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'));
});
这是因为您在使用 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'));
});