strong
首先你将 https://github.com/Free-Ma/monoapp/blob/master/turbo.json 文件增加
"@strong/api#dev": {
"dependsOn": ["@strong/utils#build"]
}
修改为
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": ["**/.env.*local"],
"tasks": {
"build": {
"dependsOn": ["^build"],
"inputs": ["$TURBO_DEFAULT$", ".env*"],
"outputs": [".next/**", "!.next/cache/**", "dist/**"]
},
"lint": {
"dependsOn": ["^lint"]
},
"dev": {
"cache": false,
"persistent": true
},
"@strong/api#dev": {
"dependsOn": ["@strong/utils#build"]
},
"@strong/admin#dev": {
"dependsOn": ["@strong/utils#build"]
}
}
}
这里需要依赖 utils 的 build 推测是因为 pnpm api:dev 命令执行时 utils 和 api 是同步编译的,api 的编译结果没有加载到 utils,包括到之后包监控成功后,再移除这步信赖配置也依然会出现同样的错误,具体原因我这边也不太明白,有兴趣的话可以自己排查一下。
预计你此时在项目根路径下运行 pnpm api:dev 会出现下列错误信息,如果没有出现请忽略
│ src/app.service.ts:2:26 - error TS2307: Cannot find module '@strong/utils' or its corresponding type declarations.
│ There are types at '/home/hank/GitHub/project-test/monoapp-master/apps/api/node_modules/@strong/utils/dist/es/in
│ dex.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating
│ to 'node16', 'nodenext', or 'bundler'.
│
│ 2 import { echoTest } from '@strong/utils';
此时你需要修改 https://github.com/Free-Ma/monoapp/blob/master/apps/api/tsconfig.json
增加如下配置
"module": "node16",
"moduleResolution": "node16"
将其修改为如下形式
{
"extends": "@strong/code/tsconfig/node.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist",
"paths": {
"@/*": ["./src/*"]
},
"module": "node16",
"moduleResolution": "node16"
},
"include": ["src", "bin", "test", "typings/**/*.d.ts", "**.js"]
}
此时再运行 pnpm api:dev 就能正常启动,但你会发现修改 utils 包中的代码 api 并不会重新加载,也就是包监控还没有生效
此时你需要删除 https://github.com/Free-Ma/monoapp/blob/master/apps/api/bin/dev.ts#L17 ext: 'js' 这行代码,使 nodemon 监控 .mjs 文件,具体参考官网 https://github.com/remy/nodemon?tab=readme-ov-file#specifying-extension-watch-list
到这里包监控就成功了