不看

时间:2016-10-04 21:09:07

标签: javascript gulp gulp-watch

请考虑以下gulp文件:

var gulp        = require('gulp');
var source      = require('vinyl-source-stream');
var browserify  = require('browserify');
var babelify    = require("babelify");
var watch       = require('gulp-watch');

gulp.task('make:engine', function() {
  return browserify({entries: [
        './src/index.js'
      ]})
      .transform("babelify")
      .bundle()
      .pipe(source('engine.js'))
      .pipe(gulp.dest('dist/'));
});

gulp.task('make:example', function() {
  return browserify({entries: [
        './examples/index.js'
      ]})
      .transform("babelify")
      .bundle()
      .pipe(source('compiled-example.js'))
      .pipe(gulp.dest('dist/example/'));
});

gulp.task('watch', ['make:engine', 'make:example'], function(){
  return watch('*.js', ['make:engine', 'make:example']);
});

gulp watch吐出:

[15:06:01] Using gulpfile ~/Documents/ice-cream-engine/gulpfile.js
[15:06:01] Starting 'make:engine'...
[15:06:01] Starting 'make:example'...
[15:06:03] Finished 'make:example' after 1.57 s
[15:06:03] Finished 'make:engine' after 1.6 s
[15:06:03] Starting 'watch'...

在任何js文件中,如果我进行编辑并保存文件,则终端不会更新以表明它正在制作引擎或示例。

项目目录如下所示:

enter image description here

我做错了什么,以至于它实际上不会在任何JS文件更改时重新编译?

1 个答案:

答案 0 :(得分:3)

根据您的屏幕截图,唯一匹配您传递给.js的glob的watch文件是gulpfile.js

如果您想要查看.jssrc目录下的所有example个文件,可以使用以下内容:

gulp.task('watch', ['make:engine', 'make:example'], function(){
  return watch(['src/**/*.js', 'examples/**/*.js'], ['make:engine', 'make:example']);
});