有了这个任务:
gulp.task("es6", function () {
return browserify({entries: 'src/main/es6/main.js', extensions: ['.js'], debug: true})
.transform(babelify)
.bundle()
.pipe(source('superpos.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('src/main/webapp'));
});
我得到这种错误日志:
清晰漂亮,我喜欢。
但是为了让我的 watch 继续运行,我需要处理错误而不是让它过去,比如
...
.transform(babelify)
.bundle()
.on('error', function(error){
// pretty error print
this.emit('end');
})
...
如何在此处重现相同的错误日志?
我宁愿通过组合 chalk、gutil 和读取错误文件来避免痛苦地重现它,而是以某种方式使用相同的函数。
最佳答案
事实证明,browserify 使用 syntax-error module从而抛出包含控制台就绪的 codeFrame
属性的丰富错误对象。
我可以这样拦截错误:
gulp.task("es6", function () {
return browserify({entries: 'src/main/es6/main.js', extensions: ['.js'], debug: true})
.transform(babelify)
.bundle()
.on('error', function(err){
if (err instanceof SyntaxError) {
gutil.log(gutil.colors.red('Syntax Error'));
console.log(err.message);
// console.log(err.filename+":"+err.loc.line);
console.log(err.codeFrame);
} else {
gutil.log(gutil.colors.red('Error'), err.message);
}
this.emit('end');
})
.pipe(source('superpos.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest('src/main/webapp'));
});
gutil 在哪里 gulp-util
对于这个结果:
关于javascript - Gulp Browserify 中的标准错误日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34175132/