繁体   English   中英

用babel gulp监视然后pm2重新启动

[英]gulp watch with babel then pm2 restart

\\嘿,我完全被这个困扰。

基本上,我希望本地开发人员能够让gulp看我的src js文件文件,并用babel对其进行转换,然后将它们输出到我的dist文件夹中,然后完成后,请让pm2 restart节点加载最新更改。

我遇到的问题是我一辈子都无法弄清楚如何添加一个要监视的回调,以便仅在babel完成魔术转换文件后才发生重新启动pm2的调用。

 var gulp = require("gulp"); var babel = require("gulp-babel"); var pm2 = require("pm2"); var watch = require("gulp-watch"); var plumber = require("gulp-plumber"); var SRC = "src/**/*js"; var DIST = "dist/"; function restartPM2() { //restart pm2 code in here } gulp.task("default", function () { return gulp.src(SRC) .pipe(watch(SRC)) .pipe(plumber()) .pipe(babel()) .pipe(plumber.stop()) .pipe(gulp.dest(DIST)); // somewhere in here need a call back after babel has transformed // the code and saved it to dist/ to then call restartPM2 }); 

任何帮助将不胜感激!

首先,您没有以正确的方式观看。 然后,您应该将事情分开。 那就是我要做的:

var paths = {
  babel: './somedir'
}

//basic babel task
gulp.task('babel', function() {
  return gulp.src(paths.babel)
  .pipe(babel())
  .pipe(gulp.dest('./'))
})

//see below for some links about programmatic pm2
gulp.task('pm2', function(cb) {
  pm2.connect(function() {
    pm2.restart('echo', function() { 
      return cb()
    })
  })
})

gulp.task('default', ['babel']) //I don't restart pm2 with the default task but you could

//the watch task
gulp.task('watch', function() {
  //their could be more watchers here ofc
  gulp.watch(paths.babel, ['babel', 'pm2'])
})

如果启动paths.babel gulp watch ,它将监视paths.babel并在更改时执行这两个任务(babel,pm2)。 如果仅执行gulp (或本例中的gulp babel ),它将启动适当的任务。 您也可以启动gulp pm2

资源:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM