typescript - 如何将 monorepo 节点项目捆绑到单个文件中?尝试使用 ncc
问题描述
所以我有一棵树
├── package.json
├── tsconfig.json
└── packages
├── lib1
│ ├── package.json
│ ├── src
│ │ ├── index.ts
│ └── tsconfig.json
├── lib2
│ ├── package.json
│ ├── src
│ │ ├── index.ts
│ └── tsconfig.json
├── graph
│ ├── package.json
│ ├── src
│ │ ├── index.ts
│ └── tsconfig.json
└── peer
├── package.json
├── src
│ └── index.ts
└── tsconfig.json
其中graph取决于lib2,它取决于lib1。
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"lib": ["es2018"],
"moduleResolution": "node",
"declaration": true,
"strict": true,
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"resolveJsonModule": true,
"outDir": "build"
},
"exclude": ["**/node_modules", "**/build", "**/dist"]
}
{
"extends": "../tsconfig-build.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
}
}
当我使用它构建时,编译时一切都很好
"scripts": {
":g:tsc": "cd $INIT_CWD && tsc --project tsconfig-build.json",
但是如果我尝试使用@vercel/ncc
,我会得到编译时错误,比如'rootDir' is expected to contain all source files.
"build": "ncc build src/index.ts",
我已经尝试在我的 中使用paths
and ,但它们都不适合我的目的,并且打字稿似乎没有正确查找不同的模块。当我将它指向对等体的 index.ts 时,它可以正常工作,但是没有工作空间依赖项。references
tsconfig.json
我的最终目标是能够将单个 js 文件发送到 docker 容器。我怎样才能达到我的目标?
解决方案
我们使用 Lerna 来管理我们的 Monorepo。
https://github.com/lerna/lerna
它允许拥有公共和私人包。公共包可以发布到注册表,并且任何依赖于来自同一个 Monorepo 的其他包的任何包都必须作为依赖项添加到 package.json 中。Lerna 可以管理依赖包中最终发生的任何更改的版本增量。
我们通过使用 GitHub 操作实现了自动部署,让 Lerna 将公共包发布到 GitHub 注册表并增加所有包,包括私有和提交到主分支的更改。
lerna.json
{
"version": "independent",
"packages": ["packages/*"],
"npmClient": "yarn",
"ignoreChanges": ["**/*.md"],
"useWorkspaces": true,
"command": {
"version": {
"conventionalCommits": true,
"createRelease": "github",
"exact": true,
"message": "chore(release): publish",
"preid": "next"
},
"publish": {
"distTag": "latest",
"preDistTag": "next",
"registry": "https://npm.pkg.github.com/"
}
}
}
推荐阅读
- css - 用 HTML/CSS 实现这种布局的最佳方式是什么?Flexbox、网格还是其他?
- c# - 关于通过 Internet 和 c# 的 p2p 连接。再次
- flutter - 在 null 上调用了方法“+”。接收方:null 尝试调用:+(123)
- r - 将行名分配给数据框
- html - 两列的高度和宽度不同(引导程序)
- git - 从 git 存储库的历史记录中删除所有 .txt 文件
- http - 发送请求时:错误请求
- powershell - Powershell Import-Module SqlServer 和 SQLPS 不相处
- python - 我正在尝试从电报频道获取消息,但是当我运行此代码时,我得到了奇怪的输出
- java - 为什么我的字体在 java(eclipse) 的字体属性中不可见?