admin管理员组文章数量:1134598
I know how to do nodemon server.js
but what if I want to do nodemon ./src
I want restart node on any changes in the directory of src
.
When I do above and it say cannot find module babelprac\src
I am also doing in another command window : 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
I aslo tried nodemon --watch ./src
. It says it can't find index.js.
I am on windows 7
My working directory is babelprac
I know how to do nodemon server.js
but what if I want to do nodemon ./src
I want restart node on any changes in the directory of src
.
When I do above and it say cannot find module babelprac\src
I am also doing in another command window : 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
I aslo tried nodemon --watch ./src
. It says it can't find index.js.
I am on windows 7
My working directory is babelprac
5 Answers
Reset to default 109Nodemon expects it just as:
nodemon --watch src server.js
https://github.com/remy/nodemon#monitoring-multiple-directories
nodemon --watch app --watch libs app/server.js
Nodemon also has a more fine-grained approach for watching folders and files. Use nodemon.json
to specify what files and the types of files to watch, as below in your case:
{
"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. 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.
Below is a good place to start your nodemon.json
.
https://github.com/remy/nodemon/blob/master/doc/sample-nodemon.md
I use this for hot replacement, nodemon --watch
src and run tsc
complier.
you can also check this article: 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
{
"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
Install it:
npm install npm-watch
"scripts":
"watch": "npm-watch"
本文标签: javascriptnodemon watch directory for changesStack Overflow
版权声明:本文标题:javascript - nodemon watch directory for changes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736861077a1955918.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论