I'm getting below error running this command
gulp.task('minify', function () { return gulp .src('public/app/js/myapp.bundle.js') .pipe(uglify()) .pipe(gulp.dest('public/app/js/myapp.bundle.min.js')); });
GulpUglifyError: unable to minify JavaScript Caused by: SyntaxError: Unexpected token: name (MenuItem) (line: 1628, col: 18, pos: 53569)
Code on that location is this
setters: [], execute: function () { class MenuItem { // <-- line 1628
What's wrong?
UglifyJS does not currently support EcmaScript 6 structures like classes.
You'll probably need to run your JavaScript through a transpiler step first, or find a minifier that knows what to do with ES6 code.
The branch of UglifyJS that is designed to work with ES6 is now published as uglify-es
on npm.
terser
is the new uglify-es
, uglify-es
is no longer maintained.
If using gulp both npmjs gulp-uglify-es and npmjs gulp-terser packages support terser.
npm install gulp-terser --save-dev
const gulp = require('gulp'); const terser = require('gulp-terser'); function es(){ return gulp.src('./src/index.js') .pipe(terser()) .pipe(gulp.dest('./build')) } gulp.task('default', es);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With