A Gatsby plugin that post-processes the output to remove the dependency on absolute URLs. The post-processed site should work when deployed at any URL prefix.
The plugin is pretty much a fork of gatsby-plugin-ifps. The difference is in how it arrives at the runtime
pathPrefix to use.
$ npm install --save @carrotsearch/gatsby-plugin-relativize
__RELATIVIZE_PREFIX__ and include the plugin in the
Then, build the project with
npm run build -- --prefix-paths. Better yet, set it by default in your
The plugin applies the following post-processing hacks:
Iterate over all output HTML files and replace every occurrence of
__RELATIVIZE_PREFIX__with the correct relative path based on the nesting depth of the file within the
__RELATIVIZE_PREFIX__with a runtime reference to
- Adds a very small code snippet to every HTML page that defines the
window.__RELATIVIZE_PREFIX__global based on the current
window.location.pathname. This ensures that Gatsby's runtime routing replaces the location with correct URLs.