TypeScript x Node.js 之热更新
发布时间:2020 年 9 月 23 号本文使用 yarn 作为包管理工具。
安装 nodemon 和 ts-node 两个库。
yarn add nodemon ts-node -D
在项目根目录下添加 nodemon 配置文件 nodemon.json。
{
"watch": ["src"],
"ext": "ts,gql",
"ignore": [],
"exec": "ts-node ./src/index.ts"
}
在终端运行 nodemon,会按照 nodemon.json 中的配置运行,当 src 目录下的 ts 或 gql 后缀的文件有变动,就会重新执行 ts-node ./src/index.ts 命令。
也可以在 package.json 的 scripts 中添加 dev 脚本。
"scripts" {
"dev": "nodemon"
}
然后在终端运行 yarn dev 即可。