[英]nodemon watch directory for changes
I know how to do nodemon server.js
but what if I want to do nodemon ./src
我知道如何做nodemon server.js
但如果我想做nodemon ./src
I want restart node on any changes in the directory of src
.我想在src
目录中的任何更改上重新启动节点。
When I do above and it say cannot find module babelprac\src
当我在上面做时,它说cannot find module babelprac\src
I am also doing in another command window : npm run scripts:watch
我也在另一个命令窗口中做: npm run scripts:watch
The script is脚本是
"scripts" : {
"scripts" : "babel src --source-maps-inline --out-dir dist",
"scripts:watch" : "babel src --watch --source-map-inline --out-dir dist"
},
That runs the watch but I want to run the script in src or dist to see the console.logs运行手表,但我想在 src 或 dist 中运行脚本以查看 console.logs
I aslo tried nodemon --watch ./src
.我也试过nodemon --watch ./src
。 It says it can't find index.js.它说它找不到 index.js。
I am on windows 7我在windows 7
My working directory is babelprac
我的工作目录是babelprac
Nodemon expects it just as: Nodemon 期望它就像:
nodemon --watch src server.js
https://github.com/remy/nodemon#monitoring-multiple-directories https://github.com/remy/nodemon#monitoring-multiple-directories
nodemon --watch app --watch libs app/server.js nodemon --watch 应用程序 --watch 库应用程序/server.js
Nodemon also has a more fine-grained approach for watching folders and files. Nodemon还有一种更细粒度的方法来查看文件夹和文件。 Use nodemon.json
to specify what files and the types of files to watch, as below in your case:使用nodemon.json
指定要监视的文件和文件类型,如下所示:
{
"watch": ["server.js", "src/"],
"ext": "js, css"
}
Having a nodemon.json
is particularly useful when the number and types of watched files start to bloat, and also when you want to run a script upon each server restart.当监视文件的数量和类型开始膨胀时,以及当您希望在每次服务器重新启动时运行脚本时,拥有nodemon.json
尤其有用。 For nodemon to read in the configuration, nodemon.json
should be placed at the root directory of your project, along with every other hidden and not hidden json files.要让nodemon读取配置, nodemon.json
应与所有其他隐藏和非隐藏 json 文件一起放在项目的根目录中。
Below is a good place to start your nodemon.json
.下面是开始你的nodemon.json
的好地方。
https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md
I use this for hot replacement, nodemon --watch
src and run tsc
complier.我将它用于热替换,nodemon --watch
src 并运行tsc
编译器。
you can also check this article: https://medium.com/netscape/start-building-web-apps-with-koajs-and-typescript-366264dec608您还可以查看这篇文章: 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"
}
This solution worked for me.这个解决方案对我有用。 In the first create a file name nodemon.json in the home directory of your project and then add this首先在项目的主目录中创建一个文件名 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"
}
you can add your directory name in the "watch" option to be monitored by the nodemon for any changes and add your files type in the "ext" option您可以在“watch”选项中添加您的目录名称,以便由 nodemon 监控任何更改,并在“ext”选项中添加您的文件类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.