問題描述
我正在使用 gulp-nodemon
config 目錄只包含一個文件 server.js.
config directory includes only one file, server.js.
$.nodemon({
script: 'config/server.js',
watch: ['config/**/*.js']
})
.on('restart', function () {
setTimeout(function () {
$.livereload.changed();
}, 1000);
});
輸出:
[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/**'
]
即使我告訴它只看配置目錄,為什么 nodemon 還要看一切?
Why does nodemon watch everything even when I tell it to watch only config directory?
從輸出中也可以看出,它只監視配置目錄 [nodemon] 監視:config/**/*.js
Also it appears from the output it only watches the config directory [nodemon] watching: config/**/*.js
推薦答案
這似乎是 nodemon 的錯誤 本身,因為我能夠使用簡單的 nodemon
命令重現它:
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"
nodemon
的默認行為是監視項目根目錄下的所有目錄,并忽略一些目錄,如 node_modules
、bower_components
或 .sass_cache
.這個默認的 ignore
實際上不起作用,但已在 此 PR 中修復.應用此修復程序,我的輸出與預期一樣.
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`
我使用這兩種配置進行了測試,即使出現警告,我的 nodemon
也沒有刷新不在指定 watched
目錄中的文件更改,并且正常工作正如預期的那樣,沒有性能問題.這更可能是對我的誤報警告.
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.
但現在我建議您堅持使用 ignore
規則,直到將其合并到 nodemon
或找到其他解決方法.
But for now I advice you to stay with your ignore
rule until this is merged into nodemon
or another workaround is found.
這里有一些相關的問題:#46, #366 和 #32
Here some related issues about that : #46, #366 and #32
這篇關于Nodemon監視選項損壞的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!