我正在使用 gulp babel 编译 es6,但似乎 uglify 正在完全剥离我的 es6。运行时,我的命令行中没有任何错误。任何想法为什么这被剥离?
我的 gulp 任务如下所示:
gulp.task('scripts', function () {
return gulp.src('src/js/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist/js'));
});
我的JavaScript:
document.addEventListener('DOMContentLoaded', function (event) {
console.log('ready to es6!');
const foo = 4;
});
输出、编译/丑化的 javascript:
"use strict";document.addEventListener("DOMContentLoaded",function(e){console.log("ready to es6!")});
//# sourceMappingURL=scripts.js.map
注意const foo = 4
被忽略了。删除正确编译的.pipe(babel())
结果。const
如果有帮助,devDependencies:
"devDependencies": {
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"browser-sync": "^2.26.3",
"gulp": "^3.9.1",
"gulp-babel": "^8.0.0-beta.2",
"gulp-sass": "^4.0.2",
"gulp-sourcemaps": "^2.6.4",
"gulp-uglify": "^3.0.1",
"node-sass": "^4.11.0"
}