我正在使用 gulp-nodemon
config目录下只有一个文件,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".
如果我包含一个忽略选项,它会修复。
ignore: [
'node_modules/**',
'bower_components/**'
]
为什么即使我告诉它只监视配置目录,nodemon 也会监视所有内容?
从输出中也可以看出它只监视配置目录 [nodemon] watching: config/**/*.js
最佳答案
这似乎是 nodemon 的错误 本身,因为我能够使用简单的 nodemon
命令重现它:
> 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
实际上不起作用,但已在 this PR 中修复.应用此修复后,我的输出与预期的一样。
> 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
目录中的文件更改,并且只工作正如预期的那样,没有性能问题。这更有可能是对我的误报警告。
但现在我建议您继续使用 ignore
规则,直到它被合并到 nodemon
或找到其他解决方法。
关于javascript - Nodemon 监视选项损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24785186/