【发布时间】:2015-07-05 08:02:45
【问题描述】:
我有以下 gulp 任务(最初来自 this blog):
var path = {
MAIN_JSX: './myapp/app/jsx/main.js',
APP_DIR: 'myapp/app',
APP_JS: 'app.js',
};
gulp.task('watch', function() {
var watcher = watchify(browserify({
entries: [path.MAIN_JSX],
transform: [reactify],
debug: true,
cache: {}, packageCache: {}, fullPaths: true
}));
return watcher.on('update', function () {
watcher
.bundle()
.on('error', function(err) {
console.log(err.message)
this.end();
})
.pipe(source(path.APP_JS))
.pipe(gulp.dest(path.APP_DIR));
console.log('Updated on ' + (new Date().toString()));
})
.bundle()
.on('error', function(err) {
console.log(err.message)
this.end();
})
.pipe(source(path.APP_JS))
.pipe(gulp.dest(path.APP_DIR));
});
gulp.task('default', ['watch']);
任务在我第一次发出 gulp 命令时运行;然后我第一次更新main.js 文件。之后它根本不运行。这里有什么问题?
【问题讨论】:
-
我看不出它本身有什么问题(尽管从
.bundle()到gulp.dest()复制代码是个坏主意)。 browserify 和 watchify 有哪些版本?如果您消除 gulp 部分,那么在main.js的后续更新中重新打包是否有任何不同?
标签: reactjs gulp browserify watchify