I have a frontend project setup with preact-cli, which leverages i18next with http-backend. This configuration is to facilitate the serving of the translations on demand from the CDN the app is to run in production on. So far I can get this to work by doing:
npx preact build --no-prerender
followed with a deploy to AWS Cloudfront
Now I would like to statically prerender some of the major routes, but regretfully, a naive: preact build --prerenderUrls ./prerender-urls.js does not work. The reason for this is that once it is to do the step of prerender-ing those routes, it is trying to leverage the i18next-http-backend in the absence of an http server running. At this point, preact build just keeps on hanging(as if I am doing a preact build --analyze).
As such, for that step, I need to use the i18next-fs-backend instead. Regretfully, while this will work for bundling in the translations on a CI/CD-server for those prerendered routes, it will not work for the translations that need to be served over the http-backend.
I only see two types of solutions to this problem:
- Do the build in two steps. First with
--no-prerenderwith ani18n.config.jsthat leverages thehttp-backendand then with--prerenderwith ani18n.config.jsthat leverages thefs-backend. The problem here is that the hashes are different between the two builds so I can not simply copy over the prerendered routes with the other build. - Setup an http server during the build that can serve those translations. This is possible in itself, but a rather brittle work-around.
There is the concept of a chained-backend with i18next that would allow me to define a fallback, but in the context of a browser, how does it make sense to have i18next-fs-backend as the primary source?
What would greatly help me at this stage is if someone can point out that
- Either there is a third viable option that I failed to consider
- Either I misunderstood some way of doing chained-backend
- Either a confirmation that I am correct and that a strong case can be made that
preact-clineeds to allow us to do the build in two parts.