0

right now I have to stop and start this gulp script to clean and rebuild my dist file and then restart the server.

My watch file is clearly wrong, what do I change for it to restart the whole gulp script when a file is edited?

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']);
Joseph Le Brech
  • 6,541
  • 11
  • 49
  • 84
  • Well...This might be the `Grant's tomb` answer...but `changedEvent` doesn't appear to exist. If that is really the case, I'm surprised it's not throwing errors. – dgo Aug 27 '14 at 23:47

2 Answers2

0

Your glob for your watch seems to be wrong. Try this:

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

Use the exclude pattern for your dist.js to avoid an infinite loop.

Ciao Ralf

RWAM
  • 6,760
  • 3
  • 32
  • 45
0

In addition to my comment above:

Instead of setting your default task as the 3 tasks you have listed, do it like this.

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.

    */
dgo
  • 3,877
  • 5
  • 34
  • 47