admin管理员组文章数量:1325155
I'm writing basic javascript using the classes syntax and trying to uglify it with gulp, but getting this error:
events.js:72
throw er; // Unhandled 'error' event
I simply used the example code from mozilla's website:
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
And nothing special about my gulp file - works perfectly for any non-class js:
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
// Lint Task
gulp.task('lint', function() {
return gulp.src('js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Concatenate & Minify JS
gulp.task('scripts', function() {
return gulp.src('js/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('dist/js'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch('js/*.js', ['lint', 'scripts']);
gulp.watch('scss/*.scss', ['sass']);
});
// Default Task
gulp.task('default', ['lint', 'scripts', 'watch']);
I'm writing basic javascript using the classes syntax and trying to uglify it with gulp, but getting this error:
events.js:72
throw er; // Unhandled 'error' event
I simply used the example code from mozilla's website:
class Polygon {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
And nothing special about my gulp file - works perfectly for any non-class js:
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
// Lint Task
gulp.task('lint', function() {
return gulp.src('js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Concatenate & Minify JS
gulp.task('scripts', function() {
return gulp.src('js/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('dist/js'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch('js/*.js', ['lint', 'scripts']);
gulp.watch('scss/*.scss', ['sass']);
});
// Default Task
gulp.task('default', ['lint', 'scripts', 'watch']);
Share
Improve this question
asked Apr 7, 2016 at 16:29
Jeff PuckettJeff Puckett
41.1k19 gold badges124 silver badges174 bronze badges
6
- 6 Classes are only available in ECMAScript6; Are you sure your environment supports ES6? – Brian Driscoll Commented Apr 7, 2016 at 16:32
- to which environment are you referring? the code works as expected in my browser, and it passes the lint. – Jeff Puckett Commented Apr 7, 2016 at 16:38
- The env where you are running gulp – Brian Driscoll Commented Apr 7, 2016 at 16:39
- How would I verify this? I'm running ubuntu 14.04.3, nodejs v0.10.44, npm 3.8.5, gulp CLI 1.2.1 local 3.9.1, gulp-uglify 1.5.3 – Jeff Puckett Commented Apr 7, 2016 at 16:47
- 1 Jeff, it would be your node.js installation. See here: kangax.github.io/pat-table/es6 – Brian Driscoll Commented Apr 7, 2016 at 17:37
1 Answer
Reset to default 6At the time, I resolved this with a workaround by transpiling to ECMA 5 with Babel.
Later I discovered it was not a problem with my Node environment as the ments led me to believe, but in fact it was because the default uglify branch used in gulp-uglify doesn't support ECMA 6 yet.
The correct solution was to instead use the harmony
branch of UglifyJS2 or to use the npm wrapper uglify-js-harmony.
本文标签: classhow to uglify javascript classesStack Overflow
版权声明:本文标题:class - how to uglify javascript classes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742153541a2423639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论