我目前已经在我的node js服务器上安装了ts-node-dev,并让它使用-- .ts标志监视我的节点文件。我的服务器正在成功地重新启动,但是当.ts文件发生更改时,我需要运行yarn build之类的命令来编译更改后的文件(或所有文件),以确保我的更改存在于重新启动的服务器中。
我似乎找不到一种在服务器重新启动时运行脚本的方法。
我尝试过这样的方法:
"start": "ts-node-dev --respawn --transpile-only yarn build && src/main.js"在我的package.json中,但它试图将我的yarn build命令解析为一个文件名。
如何将脚本绑定到重启过程中?
{
"compileOnSave": true,
"compilerOptions": {
"target": "es2017",
"lib": ["es2017", "esnext.asynciterable"],
"module": "commonjs",
"moduleResolution": "node",
"rootDir": ".",
"sourceMap": true,
"newLine": "LF",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"strict": true,
// For typeORM support
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"pretty": true,
"typeRoots": ["node_modules/@types"]
},
"include": ["src/**/*", "db/**/*", "swagger/**/*", "test/**/*"]
}这是我的tsconfig.json,如何使用监视命令指定监视所有src文件和文件夹?
发布于 2020-04-10 03:06:25
根据ts-node-dev文档,该命令为:
ts-node-dev --respawn --transpileOnly <YOUR TS FILE>您应该在package.json上试用您的启动脚本:
"dev": "ts-node-dev --respawn --transpileOnly --watch src,db,swagger,test src/main.ts"
"start": "node dist/src/main.js"在你的tsconfig.json文件中,你应该有outDir配置,这个配置定义了你编译的代码将要放置的文件夹,例如,看看我的tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "ES2017",
"moduleResolution": "node",
"outDir": "./dist",
"strict": true,
"strictPropertyInitialization": false,
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"exclude": ["node_modules"],
"include": [
"./src/**/*.tsx",
"./src/**/*.ts",
"src/__tests__",
"./src/**/*",
]
}我有outDir配置,当我运行tsc或npm run build时,会创建一个dist文件夹,里面有我所有的.js文件
https://stackoverflow.com/questions/61128328
复制相似问题