Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !12755

feat: support automatic public path

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Administrator requested to merge github/fork/amcgee/feat-auto-publicpath into main Sep 30, 2022
  • Overview 3
  • Commits 1
  • Pipelines 0
  • Changes 3

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

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/amcgee/feat-auto-publicpath