0

现在我必须停止并启动这个 gulp 脚本来清理和重建我的 dist 文件,然后重新启动服务器。

我的监视文件显然是错误的,当编辑文件时,我该如何更改以重新启动整个 gulp 脚本?

var gulp = require('gulp');
var connect = require('gulp-connect');
var concat = require('gulp-concat');
var clean = require('gulp-clean');

gulp.task('clean', function() {
  return gulp.src('app/scripts/dist.js').pipe(clean());
});

gulp.task('scripts', ['clean'], function(){
    gulp.src(['app/scripts/app.js', 'app/scripts/**/*.js', 'app/scripts/**/*/*.js'])
    .pipe(concat('app/scripts/dist.js'))
    .pipe(gulp.dest('.'));
});

gulp.task('webserver', function() {
  connect.server();
});


gulp.task('watch', ['scripts'], function(){
    gulp.watch('app/scripts' + '*.js', ['scripts']).on('change', function(evt) {
        changeEvent(evt);
    });
});


gulp.task('default', ['clean','scripts','webserver']);
4

2 回答 2

0

您的手表 glob 似乎是错误的。尝试这个:

gulp.watch(['app/scripts/**/*.js', '!app/scripts/dist.js'], ['scripts']).on('change', function(evt) {
    changeEvent(evt);
});

使用排除模式dist.js来避免无限循环。

乔拉尔夫

于 2014-08-27T14:27:12.093 回答
0

除了我上面的评论:

不要将您的默认任务设置为您列出的 3 个任务,而是这样做。

gulp.task('watch',function(){
    var scripts=gulp.watch(//scripts array,['scripts']);
    scripts.on('change,function(evt){
         changedEvt(evt) // remember to make sure this exists.
    });

gulp.task('default',['watch']);

    /* make sure to include watches for all the logic you want to get 
       executed within your watch tasks (similar to how I did it)

      #== That way, you can still call those tasks from a different shell prompt
          if you want, but they are set to always be executed when you 
          modify the related files.

    */
于 2014-08-27T23:51:46.380 回答