将 monorepo 与 App Hosting 搭配使用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助单体代码库,您可以在单个目录中组织和管理多个项目。本指南介绍了如何开始使用 App Hosting 部署基于 Nx 的应用。
使用 Firebase 控制台部署单体代码库
Firebase 控制台中的图形化后端设置流程内置了对 Monorepo 的支持。当系统在“部署设置”下提示您输入“根目录”时,请指定要部署的 monorepo 内应用的路径:

使用 Firebase CLI 部署单体代码库
单代码库支持已内置到由 Firebase CLI 命令 apphosting:backends:create
调用的后端设置流程中。进入此流程并指定所选的 GitHub 代码库后,系统会提示您指定应用的根目录(相对于代码库);在此提示中,传递要部署在 monorepo 中的应用的路径:
$ firebase apphosting:backends:create --project [project-name]
i === Import a GitHub repository
✔ Connected with GitHub successfully
? Which GitHub repo do you want to deploy? gh-username/nx-monorepo
? Specify your app's root directory relative to your repository path/to/app
例如,假设 Nx 项目结构如下,并且您要构建和部署的应用为“target-app”,那么系统会部署以下资源:
.
├── lib
├── apps
│ └── target-app
│ ├── project.json
│ └── src
│ └── ...
├── nx.json
├── package-lock.json
└── package.json
相对于代码库的应用根目录为 apps/target-app
。
排查 monorepo 部署问题
- 如果您未指定“根目录”字段,则 build 将失败,并显示一条消息,指出 App Hosting 无法在 Nx monorepo 中找到要定位的项目。
- 对于 Nx + Angular 应用,您必须使用 Angular 应用构建器来构建应用。Angular 应用构建器在
project.json
中指定
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-20。
[null,null,["最后更新时间 (UTC):2025-08-20。"],[],[],null,["\u003cbr /\u003e\n\nWith monorepos, you can organize and manage multiple projects in a single\ndirectory. This guide describes how to get started deploying Nx-based apps with\nApp Hosting.\n\nDeploy monorepos with the Firebase console\n\nMonorepo support is built into the graphical backend setup flow in the Firebase\nconsole. When prompted for a \"Root directory\" under \"Deployment settings,\"\nspecify the path to the application you want to deploy inside the monorepo:\n\nDeploy monorepos with the Firebase CLI\n\nMonorepo support is built into the backend setup flow invoked by the Firebase\nCLI command `apphosting:backends:create`. After you enter this flow and specify\nyour chosen GitHub repository, you are prompted to specify your app's root\ndirectory relative to your repository; at this prompt, pass the path to the\napplication you want to deploy inside the monorepo: \n\n $ firebase apphosting:backends:create --project [project-name]\n i === Import a GitHub repository\n ✔ Connected with GitHub successfully\n\n ? Which GitHub repo do you want to deploy? gh-username/nx-monorepo\n ? Specify your app's root directory relative to your repository path/to/app\n\nFor example, here are the assets that would be deployed given the following Nx\nproject structure and \"target-app\" as the application you want to build and\ndeploy: \n\n .\n ├── lib\n ├── apps\n │ └── target-app\n │ ├── project.json\n │ └── src\n │ └── ...\n ├── nx.json\n ├── package-lock.json\n └── package.json\n\nThe app's root directory relative to your repository is `apps/target-app`.\n\nTroubleshooting monorepo deployment\n\n- If you do not specify the \"root directory\" field, then the build will fail and display a message that App Hosting cannot find a project to target inside the Nx monorepo.\n- For Nx + Angular applications, you must use the [Angular application\n builder](https://angular.io/guide/esbuild) to build the application. The Angular application builder is specified in `project.json`"]]