part1.介紹
nodemon是一種工具,可在檢測(cè)到目錄中的文件更改時(shí)通過自動(dòng)重新啟動(dòng)節(jié)點(diǎn)應(yīng)用程序來幫助開發(fā)基于node.js的應(yīng)用程序
nodemon并沒有要求任何對(duì)你的代碼或開發(fā)的方法中的額外變化说搅。nodemon可以直接替換node指令族铆。
比如:node index.js - > nodemon index.js
part2.安裝
使用指令:
npm install -g nodemon
在全局環(huán)境下安裝nodemon
"nodemon --exec ts-node src/index.ts"
part3.配置
有兩種配置方式
創(chuàng)建nodemon.json
in nodemon.json
{
"verbose": true,
"ignore": ["*.test.js", "fixtures/*"],
"execMap": {
"rb": "ruby",
"pde": "processing --sketch={{pwd}} --run"
}
}
或者
in package.json
{
"name": "nodemon",
"homepage": "http://nodemon.io",
"...": "... other standard package.json values",
"nodemonConfig": {
"ignore": ["test/*", "docs/*"],
"delay": "2500"
}
}
PS:甚至你可以去nodemon的根目錄下找一個(gè)叫做defalut.js的文件直接更改全局配置桑李。
part4.參數(shù)介紹
-h或-help:
查看幫助菜單
指令舉例:
- nodemon -h
--exec
運(yùn)行非js程序
指令舉例:
- nodemon --exec ts-node src/index.ts 通過ts-node運(yùn)行src目錄下的index.ts
- nodemon --exec "python -v" ./app.py 通過verbose模式的python運(yùn)行app.py 注意到了嗎如果你想讓編譯的時(shí)候帶參數(shù)泼返,則需要加“ ”但如果沒有參數(shù)則不需要“ ”
--ignore
熱更新時(shí)忽略某些文件/目錄/文件模式
指令舉例:
- nodemon --ignore lib/ 忽略lib內(nèi)部文件更改
--watch
熱更新時(shí)監(jiān)視更多的文件,若這些被監(jiān)視的文件更新,則你的項(xiàng)目也會(huì)進(jìn)行熱更新
指令舉例:
nodemon --watch index.js --watch ./dist/ceshi.js
目錄結(jié)構(gòu):
in ceshi.js
console.log('in ceshi.js');
in index.js
console.log('in index.js');
此時(shí),ceshi.js如果有變動(dòng),那么控制臺(tái)會(huì)輸出in index.js,但并不包含in ceshi.js,這是因?yàn)槿肟谖募ndex.js與ceshi.js并不構(gòu)成依賴關(guān)系,但他們卻正在被監(jiān)視藐俺。
-e
默認(rèn)情況下赏壹,nodemon查找與文件.js鱼炒,.mjs,.coffee卡儒,.litcoffee田柔,和.json擴(kuò)展。您可以使用-e(或--ext)開關(guān)指定自己的列表
指令舉例:
nodemon -e js骨望,pug
現(xiàn)在pug文件更新時(shí)硬爆,也會(huì)導(dǎo)致項(xiàng)目熱更新了