I tried localizing a website using a recent guide about i18n using Gatsby, but realized that the onPostBuild function doesn't get called in debug mode (gatsby develop), and onPostBootstrap doesn't get called if there were no previous builds.
The issue can be reproduced within the following project: https://github.com/simonyiszk/mvk-web/tree/d955476403eb9d4e9c9033e2c123e9a62ed67ec6
Also, please update the blog post to include (or mention) support for prefixed paths, like done here.
EDIT: In addition to that, it turns out that storing the locales directory inside /static (relative to the project root) eliminates the need for copying it manually.
@kripod thanks for pointing out onPostBootstrap wasn't always called. Just merged PR fixing that.
onPostBuild is only called on builds so not during development.
Hey @kripod , won't using /static produce caching issues all the time? Or are filenames in this folder changed whenever the content of the respective files change?
Ran into this as well in the blog post - may be worth updating the blog post.
Also, is there anyway to get Gatsby to watch the translation/locales folder to rebuild when translations are updated? Currently need to manually restart gatsby dev
This is a problem if you are using the gatsby-plugin-algolia search plugin. The cache is only (re)generated when gatsby build is run. In the case of Algolia, the exports.createPages entry point is a viable alternative to exports.onPostBuild if you want to edit your node_modules/gatsby-plugin-algolia/gatsby-node.js file.
@mathieucaroff seems gatsby-plugin-algolia requires onPostBuild because it needs the graphql API. If onPostBootstrap had access to the graphql API then the plugin could be refactored and cache would be rebuilt properly.
I ran into this same limitation building a localization plugin and found no alternative. Hoping this hook behavior gets cleaned up or onPostBootstrap gains access to the graphql API (there could be good reason why it's not!).
@jasonmit What about using the createPages hook instead ?
Most helpful comment
@kripod thanks for pointing out onPostBootstrap wasn't always called. Just merged PR fixing that.
onPostBuild is only called on builds so not during development.