0
一直試圖使用watchify一段時間,並且我有一個保存問題。gulp watchify需要兩次保存才能包含更改
對於我所做的每一項更改,似乎都需要保存兩次,以便將更改應用到輸出中。
如果我在任何js文件中添加代碼,新添加的代碼將只顯示如果任務運行兩次。
我的代碼mainScrpits任務
var customOpts = {
entries: ['./app/app.js'],
debug: true
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
gulp.task('mainScripts', bundle);
b.on('update', bundle);
b.on('log', gutil.log);
function bundle() {
console.log('bundle');
return b.bundle()
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('main.js'))
.pipe(buffer())
.pipe(gulpif(!condition, sourcemaps.init({
loadMaps: true
})))
.pipe(gulpif(!condition, sourcemaps.write('./')))
.pipe(gulp.dest('./dist/js/'))
.pipe(gulpif(isLocal(), connect.reload()));
}
「監視」 -task
gulp.task('watch', function() {
gulp.watch('app/**/*.js', ['mainScripts']);
});
工作就像一個魅力! – Joel