Javascript 更新文件时从gulpfile触发更新

Javascript 更新文件时从gulpfile触发更新,javascript,gulp,browserify,watchify,Javascript,Gulp,Browserify,Watchify,在我的gulpfile中,index.js得到处理,提取需求,然后吐出bundle.js。问题是,即使更新了requiredfile.js,我也需要触发更新。这是我的密码: var browserify = require('browserify'), watchify = require('watchify'), gulp = require('gulp'), source = require('vinyl-source-stream'), sourceFile

在我的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
而不会造成问题)?

解决了这个问题,我添加了另一个任务来包装第一个文件,每当列出的某个文件更新时就会触发

gulp.task('watchall', function(){
    gulp.watch( ['index.js', 'js/*.js', 'js/**/*.js', 'index.html'], ['browserify']);
});

更新:这是一个较慢的更新。

弄明白了,我添加了另一个任务来包装第一个,每当列出的文件中有一个更新时就会触发

gulp.task('watchall', function(){
    gulp.watch( ['index.js', 'js/*.js', 'js/**/*.js', 'index.html'], ['browserify']);
});
更新:这是一个较慢的更新