这是我的 gulpfile.js
var gulp = require('gulp');
var browserify = require('browserify');
var source = require("vinyl-source-stream");
var reactify = require("reactify");
var watchify = require('watchify');
var gutil = require('gulp-util');
var paths = {
scripts: ['src/jsx/index.jsx']
};
gulp.task('browserify', function(){
var bundler = watchify(browserify('./src/jsx/index.jsx', watchify.args));
bundler.transform(reactify);
bundler.on('update', rebundle);
function rebundle() {
return bundler.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
.pipe(source('bundle.js'))
.pipe(gulp.dest('./public/js'));
}
return rebundle();
});
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['browserify']);
});
然后我的命令行输出如下所示:
$ gulp watch
[15:10:41] Using gulpfile ~/blizztrack/dashboard/gulpfile.js
[15:10:41] Starting 'watch'...
[15:10:41] Finished 'watch' after 9.95 ms
保存 index.jsx
[15:10:45] Starting 'browserify'...
[15:10:51] Finished 'browserify' after 5.33 s
第二次保存 index.jsx
[15:11:08] Starting 'browserify'...
[15:11:10] Finished 'browserify' after 2.02 s
第三次保存 index.jsx
没有输出。
这似乎正是我想要的前两次,然后它就停止观看。谁能指出我正确的方向?