2016-09-14 5 views
0

이 꿀꺽 꿀꺽하는 일에 관해서.
이 태스크가 실행될 때마다 (시계를 사용하기 때문에) 다른 태스크도 실행되도록 다른 태스크 scripts2를 호출 할 수 있도록 어떻게 만들 수 있습니까?작업 내에서 작업을 실행하십시오. (시계)

gulp.task('scripts', function() { 
return gulp.src(src + '/**/*.js', {read: false}) // no need of reading file because browserify does 
    .pipe(plumber()) 
    .pipe(watch(src + '/**/*.js')) // WATCH 
    // transform file objects using gulp-tap plugin 
    .pipe(tap(function (file) { 
     // replace file contents with browserify's bundle stream 
     file.contents = browserify(file.path, {debug: true}).transform('babelify', {presets: ['es2015']}).bundle(); 
    })) 
    // transform streaming contents into buffer contents (because gulp-sourcemaps does not support streaming contents) 
    .pipe(buffer()) 
    .pipe(uglify()) 
    .pipe(plumber.stop()) 
    .pipe(gulp.dest(dest)); 
}); 

답변

0

gulp-watch을 사용해야합니까? 당신이 할 수있는 한가지는 gulp에 내장 된 watch을 사용하는 것입니다. 감시 된 파일에서 변경이 감지되면 두 가지 작업을 실행하도록 설정하십시오. 다음 예에서는 gulp watcher

gulp.task('scripts2', function() { 
    console.log('hello world') 
}); 

// I've left 'scripts' identical to what you gave us, except for dropping the watch pipe 
// 
gulp.task('scripts', function() { 
    return gulp.src(src + '/**/*.js', { read: false }) // no need of reading file because browserify does 
     .pipe(plumber()) 
     // transform file objects using gulp-tap plugin 
     .pipe(tap(function(file) { 
      // replace file contents with browserify's bundle stream 
      file.contents = browserify(file.path, { debug: true }).transform('babelify', { presets: ['es2015'] }).bundle(); 
     })) 
     // transform streaming contents into buffer contents (because gulp-sourcemaps does not support streaming contents) 
     .pipe(buffer()) 
     .pipe(uglify()) 
     .pipe(plumber.stop()) 
     .pipe(gulp.dest(dest)); 
}); 

gulp.task('watcher', function() { 
    gulp.watch(src + '/**/*.js', ['scripts','scripts2']) 
}); 
관련 문제