【发布时间】:2019-12-22 03:34:30
【问题描述】:
我有一个使用 Node 和 Typescript 的相当大的项目 A。在项目 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 文件夹中:
- 分布
- moduleA.js
- moduleA.map
- moduleA.d.ts
- moduleB.js
- moduleB.map
- moduleB.d.ts
- ....
为了在另一个项目中使用这些模块A和模块B,我将以下内容添加到项目A的package.json中:
"name": "projectA",
"version": "1.0.0",
"description": "...",
"main": "dist/moduleA.js",
"typings": "dist/moduleA.d.ts",
我使用 yarn 工作空间来访问项目 A 作为项目 B 中的一个包。但问题是我只能访问模块 A,当在我的新项目 B 中使用 import {ModuleA} from 'projectA' 时?那么如何从 ProjectA 访问更多模块呢?
【问题讨论】:
标签: node.js typescript npm yarnpkg yarn-workspaces