【问题标题】:Gulp restart the server when i changed my front end(Angularjs) controller file当我更改前端(Angularjs)控制器文件时,Gulp 重新启动服务器
【发布时间】:2018-06-10 09:56:08
【问题描述】:

我有这个 gulpfile.js

// Dependencies
var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
// var notify = require('gulp-notify');
var livereload = require('gulp-livereload');

// Task
gulp.task('default', function () {
   // listen for changes
   livereload.listen();
   // configure nodemon
   nodemon({
      // the script to run the app
      script: 'server.js',
      ext: 'js'
   }).on('restart', function () {
      // when the app has restarted, run livereload.
      gulp.src('server.js')
         .pipe(livereload())
      //    .pipe(notify('Reloading page, please wait...'));
   })
})

仅当我的 server.js(服务器端)文件发生更改时,我才想重新加载 gulp,

但如果我在 angularjs controller.js 中更改了前端文件,则 gulp 重新启动服务器。

如何解决?

【问题讨论】:

    标签: javascript angularjs node.js gulp


    【解决方案1】:

    我使用 nodemon 选项 watch

    nodemon({
       // the script to run the app
       script: 'server.js',
       // comment or remove this line ext: 'js',
       ignore: ['js/controller.js'], // you can also specify directories/files to ignore
       // add watch array here
       watch: [
         //directories that you want to watch ex: src/**/*.js
         'server.js' // you can be as specific as you want try this.
       ]
    }).on('restart', function () {
       // when the app has restarted, run livereload.
       gulp.src('server.js')
          .pipe(livereload())
    //    .pipe(notify('Reloading page, please wait...'));
    })
    

    【讨论】:

    • 当我在客户端文件中进行更改时,它仍然会重新启动服务器。
    • 我认为这可能是 livereload,我相信它正在观看所有文件。我将编辑我的答案。
    • 仍在重新加载客户端:'(
    • nodemon ext 选项监视项目中具有指定扩展名的所有文件
    • 如何排除?我的 js/controller.js 文件?
    猜你喜欢
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 2014-03-22
    • 2019-02-13
    • 2019-05-07
    • 2011-11-07
    • 1970-01-01
    • 2018-11-10
    相关资源
    最近更新 更多