簡體   English   中英

nodemon 監視目錄以進行更改

[英]nodemon watch directory for changes

我知道如何做nodemon server.js但如果我想做nodemon ./src

我想在src目錄中的任何更改上重新啟動節點。

當我在上面做時,它說cannot find module babelprac\src

我也在另一個命令窗口中做: npm run scripts:watch

腳本是

"scripts" : {
  "scripts" : "babel src --source-maps-inline --out-dir dist",
  "scripts:watch" : "babel src --watch --source-map-inline --out-dir dist"
},

運行手表,但我想在 src 或 dist 中運行腳本以查看 console.logs

我也試過nodemon --watch ./src 它說它找不到 index.js。

我在windows 7

我的工作目錄是babelprac

Nodemon 期望它就像:

nodemon --watch src server.js

https://github.com/remy/nodemon#monitoring-multiple-directories

nodemon --watch 應用程序 --watch 庫應用程序/server.js

Nodemon還有一種更細粒度的方法來查看文件夾和文件。 使用nodemon.json指定要監視的文件和文件類型,如下所示:

{
  "watch": ["server.js", "src/"],
  "ext": "js, css"
}

當監視文件的數量和類型開始膨脹時,以及當您希望在每次服務器重新啟動時運行腳本時,擁有nodemon.json尤其有用。 要讓nodemon讀取配置, nodemon.json應與所有其他隱藏和非隱藏 json 文件一起放在項目的根目錄中。

下面是開始你的nodemon.json的好地方。

https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md

我將它用於熱替換,nodemon --watch src 並運行tsc編譯器。

您還可以查看這篇文章: https ://medium.com/netscape/start-building-web-apps-with-koajs-and-typescript-366264dec608

"scripts": {
  "watch-server": "nodemon --watch 'src/**/*' -e ts,tsx --exec 'ts-node' ./src/server.ts"
}

這個解決方案對我有用。 首先在項目的主目錄中創建一個文件名 nodemon.json 然后添加這個

 {
  "restartable": "rs",
  "ignore": [
    ".git",
    "node_modules/**/node_modules"
  ],
  "verbose": true,
  "execMap": {
    "js": "node --harmony"
  },
  "events": {
    "restart": "osascript -e 'display notification \"App restarted due to:\n'$FILENAME'\" with title \"nodemon\"'"
  },
  "watch": [
    "test/fixtures/",
    "test/samples/"
  ],
  "env": {
    "NODE_ENV": "development"
  },
  "ext": "js,json"
}

您可以在“watch”選項中添加您的目錄名稱,以便由 nodemon 監控任何更改,並在“ext”選項中添加您的文件類型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM