Is your feature request related to a problem? Please describe.
When I have a site with routes and I pre-render it with react-snap, JS and CSS assets are referenced by absolute path, eg <script src="/bundle.js">. The way we deploy this site, we want it to work the same when it's deployed to http://staging.example.com/branchBuild/ as it does when the same artifact (no rebuild!) is served at https://example.com/. We might have a page http://staging.example.com/branchBuild/about/team that should work the same if the URL is http://example.com/about/team (note that it's not nested under branchBuild/ here)
The problem is that react-snap generates build/about/team/index.html with its CSS and JS tags pointing to something like /bundle.js instead of ../../bundle.js.
Images are not a problem with my setup because I can do __webpack_public_path__ = getDynamicPublicPathFromUrl() upon navigation.
Describe the solution you'd like
My horrible hack is to prerender the site with react-snap, then iterate over all the HTML that was generated and use edit all script and link elements that have absolute paths, replacing those absolute paths with ones that are relative to the root of the build directory (via path.relative).
I would like react-snap to do this instead of having this weird post-prerender step.
Describe alternatives you've considered
No webpack configuration approach that I can think of would make this work, especially with the requirement that we don't rebuild it with a different publicPath.
Feature Request
Is your feature request related to a problem? Please describe.
When I have a site with routes and I pre-render it with
react-snap
, JS and CSS assets are referenced by absolute path, eg<script src="/bundle.js">
. The way we deploy this site, we want it to work the same when it's deployed tohttp://staging.example.com/branchBuild/
as it does when the same artifact (no rebuild!) is served athttps://example.com/
. We might have a pagehttp://staging.example.com/branchBuild/about/team
that should work the same if the URL ishttp://example.com/about/team
(note that it's not nested underbranchBuild/
here)The problem is that
react-snap
generatesbuild/about/team/index.html
with its CSS and JS tags pointing to something like/bundle.js
instead of../../bundle.js
.Images are not a problem with my setup because I can do
__webpack_public_path__ = getDynamicPublicPathFromUrl()
upon navigation.Describe the solution you'd like
My horrible hack is to prerender the site with
react-snap
, then iterate over all the HTML that was generated and use edit allscript
andlink
elements that have absolute paths, replacing those absolute paths with ones that are relative to the root of the build directory (viapath.relative
).I would like
react-snap
to do this instead of having this weird post-prerender step.Describe alternatives you've considered
No webpack configuration approach that I can think of would make this work, especially with the requirement that we don't rebuild it with a different
publicPath
.