最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Nodemon restart run gulp tasks - Stack Overflow

programmeradmin4浏览0评论

I have the following code in my 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'
    });
});

I need to run the scripts and lint tasks when Nodemon restarts.I have the following

gulp.task('nodemon', function () {
    nodemon({
        script: 'app.js'
    }).on('restart', function () {
        gulp.run(['scripts', 'lint']);
    });
});

Gulp.run() is now deprecated, so how would I achieve the above using gulp and best practices?

I have the following code in my 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'
    });
});

I need to run the scripts and lint tasks when Nodemon restarts.I have the following

gulp.task('nodemon', function () {
    nodemon({
        script: 'app.js'
    }).on('restart', function () {
        gulp.run(['scripts', 'lint']);
    });
});

Gulp.run() is now deprecated, so how would I achieve the above using gulp and best practices?

Share Improve this question edited Feb 7, 2014 at 7:13 TYRONEMICHAEL asked Feb 6, 2014 at 9:10 TYRONEMICHAELTYRONEMICHAEL 4,2444 gold badges31 silver badges48 bronze badges 5
  • 2 Please add a ment if you are going to down-vote my question as to why you think this question is irrelevant. – TYRONEMICHAEL Commented Feb 6, 2014 at 9:34
  • Maybe the down-voter thinks it should be clear from the doc, but indeed, (s)he should make his reasons clear. – Mangled Deutz Commented Feb 6, 2014 at 13:43
  • It's, however, not clear in the docs. – TYRONEMICHAEL Commented Feb 6, 2014 at 14:39
  • 1 A gulp-nodemon wrapper that restarts your app as you develop, and keeps your build system contained to one process. See this gulp-nodemon – vamsikrishnamannem Commented Dec 21, 2014 at 14:24
  • 2 Gotta hate frivolous downvoters. Have an upvote. – csvan Commented Jun 1, 2015 at 7:25
Add a ment  | 

2 Answers 2

Reset to default 9

gulp-nodemon documentation states that you can do it directly, passing an array of tasks to execute:

nodemon({script: 'app.js'}).on('restart', ['scripts', 'lint']);

See doc here

UPDATE, as the author of gulp-nodemon uses run as well:

Idea #1, use functions:

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();
});

If you can, use Mangled Deutz's suggestion about using functions. That's the best, most guaranteed way to make sure this works now and going forward.

However, functions won't help if you need to run dependent tasks or a series of tasks. I wrote run-sequence to fix this. It doesn't rely on gulp.run, and it's able to run a bunch of tasks in order.

发布评论

评论列表(0)

  1. 暂无评论