在Gulp Browserify中的标准错误日志
有了这个任务:
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')); });
我得到这种错误日志:
这很清楚,很漂亮,我喜欢。
但为了保持我的手表运行,我需要处理的错误,而不是让它通过,像
... .transform(babelify) .bundle() .on('error', function(error){ // pretty error print this.emit('end'); }) ...
我怎样才能在这里重现相同的错误日志?
我宁愿避免通过结合粉笔,拼写和阅读错误文件来痛苦地复制它,但是要以某种方式使用相同的function。
事实certificate,browserify使用语法错误模块 ,从而抛出包含控制台就绪的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
对于这个结果: