feat: support automatic public path#12755
Conversation
|
Hi @amcgee! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
This is unfortunately an incomplete solution - PUBLIC_URL is used for index.html template substitutions and webpack's setting |
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 forPUBLIC_URL="auto"or for including"homepage" = "auto"inpackage.json. When "auto" is specified, webpack is configured withpublicPath='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 rootindex.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 - withPUBLIC_URL=.the second script resolves to a path relative to the first script rather than relative toindex.html.It might be worth considering making "auto" the default public path value (instead of "/") when neither
homepagenorPUBLIC_URLare 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=autoas a workaround solution for #12503