I've encountered an issue while using gulp babel to compile es6. It seems that uglify is stripping out my es6 code completely. Strangely, I'm not receiving any errors in my command line during the process. Have you faced this problem before? Any suggestions on why this might be happening?
Here is a glimpse of my gulp task:
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'));
});
This is a snippet of my javascript code:
document.addEventListener('DOMContentLoaded', function (event) {
console.log('ready to es6!');
const foo = 4;
});
Upon compilation and minification, the resulting javascript code:
"use strict";document.addEventListener("DOMContentLoaded",function(e){console.log("ready to es6!")});
//# sourceMappingURL=scripts.js.map
As you can see, the const foo = 4
line is missing. Interestingly, removing the .pipe(babel())
from the gulp task allows the const
declaration to be compiled correctly.
If it helps, here are the devDependencies listed:
"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"
}