在我的 gulpfile 中,index.js
得到处理、提取需求并吐出bundle.js
. 问题是即使更新时我也需要触发requiredfile.js
更新。这是我的代码:
var browserify = require('browserify'),
watchify = require('watchify'),
gulp = require('gulp'),
source = require('vinyl-source-stream'),
sourceFile = './index.js',
destFolder = './',
destFile = 'bundle.js';
gulp.task('browserify', function() {
return browserify(sourceFile, {transform: 'reactify'})
.bundle()
.pipe(source(destFile))
.pipe(gulp.dest(destFolder));
});
gulp.task('watch', function(){
var bundler = browserify(sourceFile, {
debug: true,
cache: {},
packageCache: {},
transform: 'reactify'
});
var watcher = watchify(bundler);
return watcher.on('update', function () { // When any files update
console.log('Updating!');
var updateStart = Date.now();
watcher.bundle()
.pipe(source(destFile))
.pipe(gulp.dest(destFolder));
console.log('Updated!', (Date.now() - updateStart) + 'ms');
})
.bundle() // Create the initial bundle when starting the task
.pipe(source(destFile))
.pipe(gulp.dest(destFolder));
});
gulp.task('default', ['browserify', 'watch']);
当其他文件发生更改时,如何添加更新(不会通过运行requiredfile.js
相同的过程导致问题)?