我的gulpfile中有以下代码
gulp.task('scripts',function () {
gulp.src(paths.browserify)
.pipe(browserify())
.pipe(gulp.dest('./build/js'))
.pipe(refresh(server));
});
gulp.task('lint',function () {
gulp.src(paths.js)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('nodemon',function () {
nodemon({
script: 'app.js'
});
});
我需要在nodemon重启时运行脚本和lint任务.我有以下内容
gulp.task('nodemon',function () {
nodemon({
script: 'app.js'
}).on('restart',function () {
gulp.run(['scripts','lint']);
});
});
Gulp.run()现在已被弃用,那么我如何使用gulp和最佳实践来实现上述目标?
解决方法
gulp-nodemon文档说明你可以直接执行它,传递一组任务来执行:
nodemon({script: 'app.js'}).on('restart',['scripts','lint']);
见doc here
更新,因为gulp-nodemon的作者也使用run:
想法#1,使用功能:
var browserifier = function () {
gulp.src(paths.browserify)
.pipe(browserify())
.pipe(gulp.dest('./build/js'))
.pipe(refresh(server));
});
gulp.task('scripts',browserifier);
var linter = function () {
gulp.src(paths.js)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('lint',linter);
nodemon({script: 'app.js'}).on('restart',function(){
linter();
browserifier();
});