javascript - Nodemon 监视选项损坏

标签 javascript node.js gulp nodemon

我正在使用 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_modulesbower_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 或找到其他解决方法。

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

关于javascript - Nodemon 监视选项损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24785186/

相关文章:

javascript - 在Android中如何通过socket.io发送带有参数的POST/GET或通过socket.io调用feathersjs服务?

javascript - 如何使用 JavaScript 将 HTML 转换为 Docx 和 PDF

sass - 找不到要导入的文件或无法读取 : compass - Gulp environment

javascript - 如何根据 Django 下拉菜单中的选择显示和隐藏表单字段

javascript - 将 Canvas 缩放到鼠标光标

javascript - 如何使用Python/CGI进行文件上传

javascript - 单击输入值外部后向输入值添加空格

node.js - 如何在 Linux 上的 Azure 应用服务上运行时远程实时调试 Node.js 应用程序

javascript - 捕获 gulp-mocha 错误

css - 如何为 gulp-concat-css 的输入文件设置适当的基础?