Gulp Nodemon不运行任务

时间:2018-10-18 21:44:07

标签: javascript node.js gulp

这是我的gulpfile.babel.js

const gulp = require('gulp');
const gulpLoadPlugins = require('gulp-load-plugins');
const path = require('path');
const del = require('del');
const runSequence = require('run-sequence');


const plugins = gulpLoadPlugins();

const paths = {
  js: ['./src/**/*.js', '!dist/**', '!node_modules/**'],
  nonJs: ['./package.json', './.gitignore', './.env'],
};

// Clean up dist and coverage directory
gulp.task('clean', () => del(['dist/**', 'dist/.*', '!dist']));

// Copy non-js files to dist
gulp.task('copy', () => gulp.src(paths.nonJs)
  .pipe(plugins.newer('dist'))
  .pipe(gulp.dest('dist')));

// Compile ES6 to ES5 and copy to dist
gulp.task('babel', () => gulp.src([...paths.js, '!gulpfile.babel.js'], { base: '.' })
  .pipe(plugins.newer('dist'))
  .pipe(plugins.sourcemaps.init())
  .pipe(plugins.babel())
  .pipe(plugins.sourcemaps.write('.', {
    includeContent: false,
    sourceRoot(file) {
      return path.relative(file.path, __dirname);
    },
  }))
  .pipe(gulp.dest('dist')));


// Start server with restart on file changes
gulp.task('nodemon', ['copy', 'babel'], () => plugins.nodemon({
  script: path.join('dist/src', 'app.js'),
  ext: 'js',
  ignore: ['node_modules/**/*.js', 'dist/**/*.js'],
  tasks: ['copy', 'babel'],
  nodeArgs: ['--inspect', '--inspect-brk'],
}));

// gulp serve for development
gulp.task('serve', ['clean'], () => runSequence('nodemon'));

// gulp build for building application
gulp.task('build', ['clean'], () => {
  runSequence(
    ['copy', 'babel'],
  );
});

// default task: clean dist, compile js files and copy non-js files.
gulp.task('default', ['clean'], () => {
  runSequence(
    ['copy', 'babel'],
  );
});

clonecopybabel任务有效,nodemon首次启动时也有效,但是在文件更改时,nodemon重新运行但它不会重新编译我的文件。我在tasks参数中有两个任务:复制以将nonJs文件复制到dist/和babel来编译文件并将它们复制到dist/-两者都应该在检测到更改之后完成,但是它们不是t-按下CTRL + S后,nodemon重新启动,但使用来自dist/的相同旧版本的文件。我在这里做什么错了?

0 个答案:

没有答案