我有一个相当大的项目 A 使用 Node 和 Typescript。在项目 A 中,我有很多不同的模块,我想在另一个项目 B 中重用它们。
因此我用这个 tsconfig.json 构建了项目 A:
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"sourceMap": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"typeRoots": ["./node_modules/@types", "./modules/@types"]
},
"exclude": ["node_modules"]
}
因此所有文件都以这种方式构建到 /dist 文件夹中:
- dist
- moduleA.js
- 模块A.map
- 模块广告
- moduleB.js
- moduleB.map
- 模块B.d.ts
- ....
为了在另一个项目中使用这些 moduleS 和 module,我将以下内容添加到项目 A 中的 package.json 中:
"name": "projectA",
"version": "1.0.0",
"description": "...",
"main": "dist/moduleA.js",
"typings": "dist/moduleA.d.ts",
我使用纱线工作区来访问项目A作为项目B中的包。但问题是,当使用时我只能访问模块Aimport {ModuleA} from 'projectA'
在我的新项目 B 中?那么如何从 ProjectA 访问更多模块呢?