Nodemon watch option broken

2019-04-08 21:05发布

问题:

I am using gulp-nodemon

config directory includes only one file, server.js.

$.nodemon({
  script: 'config/server.js',
  watch: ['config/**/*.js']
})
.on('restart', function () {
  setTimeout(function () {
    $.livereload.changed();
   }, 1000);
 });

Output:

[gulp] [nodemon] v1.2.1
[gulp] [nodemon] to restart at any time, enter `rs`
[gulp] [nodemon] watching: config/**/*.js
[gulp] [nodemon] starting `node config/server.js`
[gulp] [nodemon] watching 34,325 files - this might cause high cpu usage. To reduce use "--watch".

If i include an ignore option it fixes.

ignore: [
  'node_modules/**',
  'bower_components/**'
]

Why does nodemon watch everything even when I tell it to watch only config directory?

Also it appears from the output it only watches the config directory [nodemon] watching: config/**/*.js

回答1:

This seems to be a bug with nodemon itself, because I was able to reproduce it using the simple nodemon command :

> nodemon --watch app server.js
[nodemon] v1.2.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: app/**/*
[nodemon] starting `node server.js`
[nodemon] watching 72,981 files - this might cause high cpu usage. To reduce use "--watch"

The default behavior of nodemon is to watch all the directories in the root of your project, and to ignore some directories like node_modules, bower_components or .sass_cache. This default ignore don't work actually, but was fixed in this PR. Applying this fix, my output was just as expected.

> nodemon --watch app server.js
[nodemon] v1.2.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: app/**/*
[nodemon] starting `node server.js`

I tested using both configurations, and even with the warning, my nodemon was not refreshing on a file change that is not in the specified watched directory, and working just as expected with no performance issue. It's more likely a false-positive warning to me.

But for now I advice you to stay with your ignore rule until this is merged into nodemon or another workaround is found.

Here some related issues about that : #46, #366 and #32