简体   繁体   English

如何确定运行browserify的gulp任务何时完成?

[英]How to determine when the gulp task running browserify is complete?

I have such a gulp task 我有这样一个gulp任务

gulp.task("js-min", function () {
  browserify(config.paths.mainJs)
    .transform(reactify)
    .bundle()
    .pipe(source('tec.min.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(uglify())
    .pipe(sourcemaps.write(config.paths.dist))
    .pipe(gulp.dest(config.paths.dist));
});

that create the minified version of the application. 创建应用程序的缩小版本。 It runs periodically by the gulp-watch task. 它通过gulp-watch任务定期运行。 The problem I see, is that gulp tells me this task finishes in 30ms, but if I check the file being generated, it takes another 30s to see the actual new file being updated. 我看到的问题是, gulp告诉我这个任务在30ms完成,但是如果我检查正在生成的文件,则需要另外30秒才能看到正在更新的实际新文件。

How shall I change the gulp task js-min so I know exactly when the file was finished updating in file system. 如何更改gulp任务js-min以便确切知道文件系统中文件何时完成更新。

There are two solutions, and without knowing what browserify package you are using. 有两种解决方案,并且不知道您使用的是什么browserify包。

If it is promise based, then simply edit your code to return that promise: 如果它是基于promise的,那么只需编辑您的代码即可返回该承诺:

gulp.task("js-min", function () {
   return  browserify(config.paths.mainJs)

If it is not promise-based, then it will have some kind of an onend or done method that takes a callback. 如果答应为主,那么它将有某种的的onenddone法,需要一个回调。 In that case, it would be like this: 在这种情况下,它会是这样的:

gulp.task("js-min", function (done) {
  browserify(config.paths.mainJs)
    .transform(reactify)
    .bundle()
    .pipe(source('tec.min.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(uglify())
    .pipe(sourcemaps.write(config.paths.dist))
    .pipe(gulp.dest(config.paths.dist))
    // THIS IS THE LINE TO CHANGE
    .onfinish(done);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM