Gulp Uglify 选项不适用
Gulp Uglify Options not applying
您好,我正在为我工作的公司制作主题,JS 片段无法在 uglify 中正确构建。我正在尝试使用 uglify 简单地连接我的文件,这有效,但它们输出缩小和损坏,没有评论,我无法弄清楚为什么,下面是我的 gulp 任务,它运行正确但没有输出提供的选项
gulp.task('js', function() {
return gulp.src('./src/js/*.js')
.pipe(uglify({
options: {
mangle: false,
beautify: true,
comments: true
}
}))
.pipe(rename('cf247bootstrapTheme.js'))
.pipe(gulp.dest('./dist/js'));
});
知道为什么会这样吗?
谢谢,
基兰
可能选项没有按预期传递。
为丑化管道试试这个:
.pipe(uglify({
mangle: false,
output: {
beautify: true,
comments: true
}
})
这些选项在 UglifyJS readme 中可用。
匹配问题内容的示例配置(+控制台):
.pipe(uglify({
// https://github.com/mishoo/UglifyJS#mangle-options
mangle: {
toplevel: false
},
// https://github.com/mishoo/UglifyJS#compress-options
compress: {
drop_console: false
},
// https://github.com/mishoo/UglifyJS#output-options
output: {
beautify: true,
comments: true,
preamble: "/* Licensing info */"
}
}))
对于生产构建,您可能需要考虑使用:
.pipe(uglify({
// https://github.com/mishoo/UglifyJS#mangle-options
mangle: {
toplevel: true
},
// https://github.com/mishoo/UglifyJS#compress-options
compress: {
drop_console: true
},
// https://github.com/mishoo/UglifyJS#output-options
output: {
beautify: false,
comments: false,
preamble: "/* Licensing info */"
}
}))
您好,我正在为我工作的公司制作主题,JS 片段无法在 uglify 中正确构建。我正在尝试使用 uglify 简单地连接我的文件,这有效,但它们输出缩小和损坏,没有评论,我无法弄清楚为什么,下面是我的 gulp 任务,它运行正确但没有输出提供的选项
gulp.task('js', function() {
return gulp.src('./src/js/*.js')
.pipe(uglify({
options: {
mangle: false,
beautify: true,
comments: true
}
}))
.pipe(rename('cf247bootstrapTheme.js'))
.pipe(gulp.dest('./dist/js'));
});
知道为什么会这样吗?
谢谢,
基兰
可能选项没有按预期传递。
为丑化管道试试这个:
.pipe(uglify({
mangle: false,
output: {
beautify: true,
comments: true
}
})
这些选项在 UglifyJS readme 中可用。
匹配问题内容的示例配置(+控制台):
.pipe(uglify({
// https://github.com/mishoo/UglifyJS#mangle-options
mangle: {
toplevel: false
},
// https://github.com/mishoo/UglifyJS#compress-options
compress: {
drop_console: false
},
// https://github.com/mishoo/UglifyJS#output-options
output: {
beautify: true,
comments: true,
preamble: "/* Licensing info */"
}
}))
对于生产构建,您可能需要考虑使用:
.pipe(uglify({
// https://github.com/mishoo/UglifyJS#mangle-options
mangle: {
toplevel: true
},
// https://github.com/mishoo/UglifyJS#compress-options
compress: {
drop_console: true
},
// https://github.com/mishoo/UglifyJS#output-options
output: {
beautify: false,
comments: false,
preamble: "/* Licensing info */"
}
}))