【问题标题】:watching folder using nodemon使用 nodemon 监视文件夹
【发布时间】:2021-12-12 12:23:21
【问题描述】:

我正在尝试查看我的 src 文件夹中的更改,该文件夹中会有多个 js 文件。我怎样才能做到这一点?当我运行 dev 脚本时,我从索引文件中获取 console.log,但不是从 world 和 hello 文件中获取。谁能解释我如何才能让所有 console.log 出现?

目录:

folder
 ├── src
 |   ├── hello.js
 |   ├── index.js
 |   └── world.js
 | .gitignore
 | package.json
 | README.md

package.json:

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "src",
  "scripts": {
    "dev": "nodemon --watch src"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "nodemon": "^2.0.14"
  }
}

src 中的文件:

// index.js
console.log('index.js')
// world.js
console.log('world.js')
// hello.js
console.log('hello.js')

【问题讨论】:

    标签: node.js nodemon


    【解决方案1】:

    Nodemon 启动单个 .js 文件作为入口点,这将是您的 index.js。如果您的此文件未导入其他文件以执行其中的代码,您将看不到其他 console.log

    您可以查看this answer,了解如何在多个文件上并排运行 nodemon。

    【讨论】:

    • 我明白了,谢谢你的回答。我正在查看您给我的答案,以便我可以大致了解一下。我很好奇的一个问题是,package.json 中的主要入口点在这种情况下是否重要?
    猜你喜欢
    • 2015-01-24
    • 2020-09-21
    • 2019-02-20
    • 2017-03-08
    • 1970-01-01
    • 2012-10-05
    • 2018-07-11
    • 2018-06-03
    • 2021-07-05
    相关资源
    最近更新 更多