为了部署我的 Angular 项目,我运行了
ng build --configuration production
,然后运行了 firebase deploy --only hosting
。它说:
Thank you for trying our early preview of Angular support on Firebase Hosting.
During the preview, support is best-effort and breaking changes can be expected. Proceed with caution.
Documentation: https://firebase.google.com/docs/hosting/frameworks/angular
File a bug: https://github.com/firebase/firebase-tools/issues/new?template=bug_report.md
Submit a feature request: https://github.com/firebase/firebase-tools/issues/new?template=feature_request.md
We'd love to learn from you. Express your interest in helping us shape the future of Firebase Hosting: https://goo.gle/41enW5X
Error: No i18n config on project.
我安装了 Transloco 5.0.7。阅读如何配置国际化(i18n)重写,Firebase Hosting 似乎正在寻找这个:
"i18n": {
"root": "/localized-files"
},
在
firebase.json
。它期望在 localized-files
目录中看到 public
:
public/localized-files/
我的 Angular 应用程序没有这个目录结构。我有:
src/app/assets/i18n/
我试过了
"i18n": {
"root": "src/app/assets/i18n/"
},
"i18n": {
"root": "app/assets/i18n/"
},
"i18n": {
"root": "/assets/i18n/"
},
和
"i18n": {
"root": "assets/i18n/"
},
这些都会引发类似的错误:
hosting: Couldn't find specified i18n root directory /assets/i18n in public directory .
firebase.json
中是否还有另一个配置行告诉Firebase Hosting Angular将index.html
放入app
目录中,而不是public
目录中?
我想通了。我读过的两页文档是:
如果您已安装并运行 Transloco,则无需触摸其中的任何内容。找到包含 Transloco 文件的文件夹。我的文件夹在
src/app/assets/i18n
打开
firebase.json
并进行两项更改。首先,输入您的i18n
文件夹的路径:
"i18n": {
"root": "/assets/i18n"
},
接下来,删除行
"source": ".",
并将其替换为包含 index.html
文件的文件夹的路径。 Firebase 将此称为您的 public
目录。
"public": "src/app",
这是我的整个
firebase.json
文件:
{
"hosting": {
"public": "src/app",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"i18n": {
"root": "/assets/i18n"
},
"frameworksBackend": {
"region": "us-central1"
}
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"storage": {
"rules": "storage.rules"
},
"emulators": {
"auth": {
"port": 9099
},
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"hosting": {
"port": 5000
},
"storage": {
"port": 9199
},
"ui": {
"enabled": true
},
"singleProjectMode": true
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
]
}