簡體   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