问题描述
我目前有一个具有以下结构的lerna / react / TS项目:
.
├── lerna.json
├── package.json
├── packages
│ ├── patient
│ │ ├── package.json
│ │ ├── src
│ │ │ └── index.tsx
│ │ ├── tsconfig.build.json
│ │ └── tsconfig.json
│ └── appointment
│ ├── package.json
│ ├── src
│ │ └── index.tsx
│ ├── tsconfig.build.json
│ └── tsconfig.json
├── tsconfig.build.json
└── tsconfig.json
在packages/appointment/src/index.tsx
中,其导入patient
模块:
import { Patient } from '@ui-sdk/patient';
在tsc --project ./tsconfig.build.json
文件夹中运行构建命令appointment
时,它会再次添加patient
代码。
实际:
/packages/appointment/dist/patient/index.js
/packages/appointment/dist/appointment/index.js
预期:
/packages/appointment/dist/index.js
/packages/appointment/tsconfig.build.json
处的构建配置如下:
{
"extends": "../../tsconfig.build.json","compilerOptions": {
"outDir": "./dist","jsx": "react","esModuleInterop": true
},"include": [
"src/**/*"
]
}
和根级别的主要tsconfig.json
:
{
"compilerOptions": {
"module": "esnext","target": "es5","lib": [
"dom","dom.iterable","esnext"
],"skipLibCheck": true,"sourceMap": true,"resolveJsonModule": true,"moduleResolution": "node","declaration": true,"baseUrl": ".","paths": {
"@ui-sdk/*": ["packages/*/src"]
},},"exclude": [
"node_modules","dist"
]
}
如果我删除此部分:
"baseUrl": ".",
编译抛出错误
packages/appointment/src/index.tsx(2,24): error TS2307: Cannot find module '@ui-sdk/patient' or its corresponding type declarations.
有什么主意如何使构建仅包含该组件的代码,而不是将其他文件放入构建文件夹中?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)