【发布时间】:2018-04-26 04:33:08
【问题描述】:
当我在 browserify 捆绑器中包含 watchify 插件并且出现编译时错误时,不会记录该错误。
const gulp = require('gulp');
const browserify = require('browserify'); //js bundler
const watchify = require('watchify'); //allows incremental bundling
const hbsfy = require('hbsfy'); //precompiles hbs files
const babelify = require('babelify'); //ES2015 to ES5
const source = require('vinyl-source-stream'); //Gulp and NodeJS stream interop. Use conventional text streams at the start of your gulp or vinyl pipelines, making for nicer interoperability with the existing npm stream ecosystem.
const buffer = require('vinyl-buffer'); //Convert streaming vinyl files to use buffers. Usually used with vinyl-source-stream and gulp-sourcemaps
const uglify = require('gulp-uglify'); //uglifyjs (js minimalizer) plugin for gulp (would be nice to use uglyfyjs directly)
const sourcemaps = require('gulp-sourcemaps'); //generate source maps when tranforming js or css
const gutil = require('gulp-util'); //utlis for gulp, e.g. console logging
gulp.task("watch-js", function(done){
var b = browserify({
entries: 'main.js',
debug: true,
cache: {},
packageCache: {},
});
b.external(config.vendorJsLibs);
b.transform(hbsfy);
b.transform(babelify, { presets: ['es2015'] });
b.plugin(watchify); //when I comment this, errors are reported
b.on('error', function(err){
gutil.log(err.toString());
this.emit('end');
done();
});
compileJs(b, 'app.js');
b.on('update', function(evt){
gutil.log('watchify update '+ evt);
compileJs(b, 'app.js');
});
});
function compileJs(bundler, bundleFileName){
return bundler.bundle()
.pipe(source(bundleFileName))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.on('error', function(error){
gutil.log(error);
this.emit('end');
})
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(dest + '/scripts'));
}
【问题讨论】:
-
您的报价有问题。
entries: "main.js',应该是entries: 'main.js',。修复后错误是否仍然存在? -
@MenzoWijmenga:修复谢谢。这是在这里写问题时的错字。所以是的,它仍然存在。为了清楚起见,您可以删除您的评论
标签: gulp browserify watchify