feat(react-scripts): allow PUBLIC_URL in develoment mode#7259
feat(react-scripts): allow PUBLIC_URL in develoment mode#7259andriijas merged 1 commit intofacebook:masterfrom unrevised6419:public-url-in-development
Conversation
ArnaudBarre
left a comment
There was a problem hiding this comment.
packages/react-scripts/config/webpack.config.js L. 561-563 to update
|
@ArnaudBarre done! |
mrmckeb
left a comment
There was a problem hiding this comment.
@iansu or @ianschmitz - can I get your thoughts on this one?
|
@iansu @Timer @gaearon @amyrlam @ianschmitz @petetnt @bugzpodder please review this PR, if all good merge it ASAP and make release please 🙏 , my projects requires and also I don't want to eject since we don't have enough resource to setup packer env 😢 |
|
@sambathl I'm chasing a second review on this, and then we can merge it in. |
|
I don't think it works when |
|
I think all that needs to change is webpackDevServer.config.js needs to check for the relative path when setting publicPath. publicPath: paths.servedPath === "./" ? "/" : paths.servedPath.slice(0, -1) |
|
There is also a problem when setting homepage Edit: In this case dev server just served clear |
|
@iamandrewluca Hm, I'm actually not getting that anymore with my changes, so maybe the PUBLIC_URL thing was fixed by ad7e29b? But the dev server is definitely serving index.html when requests for |
|
@iamandrewluca not sure if merging in master will fix the build issue / or at least rerun the build? |
|
@raix made a rebase to trigger the build. It seems there is a babel plugin dependency error comming from master. |
|
I'm trying this branch. I'm curious about why the public url have to end with a slash? If I set the public_url with for example: "PUBLIC_URL=/test" and browse http://localhost:3000/test, it redirects the url to: http://localhost:3000/test/test Btw, thanks for this PR, it's very useful. |
It should not, I'll check. |
|
Another thing I noticed is that when reloading http://localhost:3000/test/some-path, it returns a 404 error. Reloading http://localhost:3000 works. I don't know if it's related, but I'm running the apps behind a reverse proxy (nginx). |
|
@lucasmogari on |
|
@lucasmogari shouldn't it be: |
|
It actually works both ways. According to nginx docs: https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
The refresh problem happens in both ways too. I think there's something related to what is described in the docs, but there's no guide for nginx. https://create-react-app.dev/docs/deployment/#serving-apps-with-client-side-routing |
Yes. What I'm trying to do: http://localhost:3000 proxies to http://localhost:3010/ (main app) In dev, refreshing http://localhost:3000/some-path works, but http://localhost:3000/test/some-path returns 404. |
|
I found that adding the option (index: paths.publicUrlOrPath) to webpackDevServer.config.js fixed the problem with refreshing: |
|
Just a kind reminder - in 5 days / the 26th of January the original pr for this pull-request turns 1 year. Not often pull-requests live this long so I'm not sure if I should bring cake or flowers? :) (Disclaimer: I'm not trying to push or rush things - even if we desperately want this to be merged) |
|
@raix 😄 will live till will be merged 🌹 🌷 💮 |
|
@iamandrewluca Can you rebase locally and push? |
|
@lucasmogari I addressed the issues you encoutnered, can you try again with the proxy?
@andriijas done! |
|
PR Blocked by a |
|
@iamandrewluca In case we forget, ping when |
|
Ok, I'll ping. Contacted a webpack maintaner for an ETA. |
With PUBLIC_URL=/test With PUBLIC_URL=/test/ Maybe it's some configuration here. I'm sorry, but I don't have too much time to debug right now. Thanks again! |
|
@lucasmogari Try in incognito mode. Or clear all data for If I open |
Co-authored-by: Eric Clemmons <eric@smarterspam.com> Co-authored-by: Alex Guerra <alex@heyimalex.com> Co-authored-by: Kelly <kelly.milligan@gmail.com>
|
@andriijas all done! Need review. |
|
Thanks for your patience everyone, specially @iamandrewluca If anyone wants to do additional testing on their projects - please do! |
|
Well done! |
|
I encountered some problems when using proxy with this feature. Investigating. Think I should reorder in a right way proxy middlewares. Also one case Do we revert the PR, and create a new one with fixed problems, or we fix the problem till the next release? |
|
Found the issue. Will make a PR soon. Internal proxy that decides to proxy or not, does not know about public path |
Allow
PUBLIC_URLin development modereact-dev-utils/getPublicUrlOrPath)redirectServedPathMiddlewareandgetPublicUrlOrPathDefinitelyTyped/DefinitelyTyped#40982Public API
react-dev-utils/redirectServedPathMiddleware)contentBasePublicPathoption webpack/webpack-dev-server#2150)/Private API
paths.publicUrlandpaths.servedPathintopaths.publicUrlOrPathreact-dev-utils/getPublicUrlOrPath(no side effects)evalSourceMapMiddlewareanderrorOverlayMiddlewarefirst in the middleware chain, redirect does not affect them.PUBLIC_URLnoopServiceWorkerMiddlewareto serve fromservedPathwebpack-dev-server@3.9.0towebpack-dev-server@3.10.0Blocked by webpack/webpack-dev-server/pull/2150Blocked by webpack/webpack-dev-server/pull/2374Blocked by https://github.com/webpack/webpack-dev-server new patch releaseCloses #6280
Closes #6135
Closes #4158