Emidomenge
Emidomenge

Reputation: 1524

Deploy Angular 10 app with localize using Firebase

I'm using Angular 10 (the last version at the moment) and @angular/localize to translate my app into french and english.

Everything is well configured.

For the build, I'm using this command:

"build:prod": "ng build --prod --localize"

which gives:

enter image description here

I want to deploy the app using Firebase. I correctly set everything when running firebase init hosting

firebase.json looks like:

{
  "hosting": {
    "public": "dist/myAngularApp",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

Now my issue is that there is no index.html file at the root of dist/myAngularApp so when deploying and targeting default url, nothing is displayed.

For example:

I want to render the english version of the app by default and I expected, I could specify it when building my project using a specific option or inside angular.json file.

Any idea ?

Thank you !

Upvotes: 1

Views: 764

Answers (2)

amc software
amc software

Reputation: 865

Now you can set up i18n rewrites. Please add this:

//firebase.json

"i18n": {
    "root": "localized-files" //directory that contains your i18n folders
 }

Firebase serves content based on the values of the "Accept-Language" header

Complete reference at: https://firebase.google.com/docs/hosting/i18n-rewrites

Upvotes: 2

Poul Kruijt
Poul Kruijt

Reputation: 71901

Add a rewrite rule to your hosting object in your firebase.json:

"rewrites": [ 
  { "source": "**", "destination": "/en/index.html"} 
]

Upvotes: 4

Related Questions