Created by: amcgee
This solution is incomplete - it will unfortunately need to touch a many more places in several packages to work in all cases.
WebPack 5 includes support for automatically determining the public path by passing publicPath='auto'
. This change adds support for PUBLIC_URL="auto"
or for including "homepage" = "auto"
in package.json
. When "auto" is specified, webpack is configured with publicPath='auto'
and the resulting webpack build will automatically determine the base path on load.
This is useful when the root path is not known at build time. It has been possible to specify PUBLIC_URL=.
which correctly resolves most resources relative to the root index.html
- however, in some cases (for example when launching a WebWorker) this causes issues when a script attempts to reference another script with a path relative to the base path - with PUBLIC_URL=.
the second script resolves to a path relative to the first script rather than relative to index.html
.
It might be worth considering making "auto" the default public path value (instead of "/") when neither homepage
nor PUBLIC_URL
are specified. This should be a non-breaking change (and should reduce the need for specifying this configuration at all) but I opted for leaving it out of this change to keep the surface area small. I would suggest that after this has been used as an opt-in configuration for some time it could be promoted to the default in a future release of Create React App.
This allows PUBLIC_URL=auto
as a workaround solution for #12503