6

我正在使用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

4

1 回答 1

18

这似乎是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实际上不起作用,但已在此 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或找到另一个解决方法。

这里有一些相关的问题:#46#366#32

于 2014-07-30T18:14:39.543 回答