-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(react-scripts): allow PUBLIC_URL in develoment mode #7259
feat(react-scripts): allow PUBLIC_URL in develoment mode #7259
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/react-scripts/config/webpack.config.js L. 561-563 to update
@ArnaudBarre done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iansu or @ianschmitz - can I get your thoughts on this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fixes the issue I mentioned at #6280 (comment) 👍
@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 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_URL
in development modereact-dev-utils/getPublicUrlOrPath
)redirectServedPathMiddleware
andgetPublicUrlOrPath
DefinitelyTyped/DefinitelyTyped#40982Public API
react-dev-utils/redirectServedPathMiddleware
)contentBasePublicPath
option webpack/webpack-dev-server#2150)/
Private API
paths.publicUrl
andpaths.servedPath
intopaths.publicUrlOrPath
react-dev-utils/getPublicUrlOrPath
(no side effects)evalSourceMapMiddleware
anderrorOverlayMiddleware
first in the middleware chain, redirect does not affect them.PUBLIC_URL
noopServiceWorkerMiddleware
to serve fromservedPath
webpack-dev-server@3.9.0
towebpack-dev-server@3.10.0
Blocked 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