-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix hmr in docker + support devServer.public with protocol
- Loading branch information
Showing
1 changed file
with
11 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
da38ed4
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.
@yyx990803 thanks for this I am wondering if we can maybe take the same approach that we did with gatsby here? https://github.com/gatsbyjs/gatsby/pull/9734/files
I am having issue trying to set this to
/
but because of the relative regex requiring a:
it doesn't match so I am forced to put an absolute path here.da38ed4
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.
@drubin, why would you want to use
/
indevServer.public
option, isn'tbaseUrl
option fit for you?da38ed4
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.
@jkzing Thanks for quick reply.
The full discussion can be found gatsbyjs/gatsby#8348 (comment) I had the same issue with Gatsbyjs (underlying webpack library) so I think applying similar logic here would make sense.
The summary is that when building demos or reusable configs you often don't know what the public endpoint/ip will be and users might want a custom domain name.
Gatsby originally defaulted the HMR url to
--host
similar to--public
param which seemed like a good default unless you are running behind docker/vagrant/proxy server of some kind. In which case the IP address you bind to on your local machine won't always be the same DNS name that the web browser will access it from.I think this might solve many of the IP/host issues around docker/vagrant/proxies as it did with Gatsby.
Let's take from example a simple setup.
You run Vue CLI inside docker (shareable configs and easier to get started) the docker containers IP is 192.168.1.20. Your vue configuration would be
vue-cli-service serve --host=0.0.0.0 ---public=http://192.168.1.20/
so it binds to the public IP address but now the HMR endpoint defaults to thehttp://192.168.1.20/
? now you restart your docker container and the IP address changes to 192.168.1.21.. so you have to change the configuration again if you were able to default it to/
you would just be able to restart it.In the PR above we changed the default endpoint to allow relative pathing i.e
/
as a default so that when you change configuration dns/ip you don't need to also modify your configuration and rebuild/compile.Because of the regex check here, I am unable to leave off the port + hostname and pass a configuration like
--public=/
as it automatically replaces it to--protocol
and--public
I am not sure where it came from but you can pass relative paths into
require.resolve(
webpack-dev-server/client) + sockjsUrl,
as shown but the Gatsby PR.Hope this explains it clearly if not please let me know and I will show you an example.
So even if you don't change the default. Would you be open to accepting a PR removing the regex check to allow purely relative URLs?
da38ed4
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.
@drubin Understood.
The current behavior we used to infer sockjs url is to support use case that
dev-server
is started behind a reverse proxy (see #1472 (comment)). As we have abaseUrl
option invue.config.js
,devServer.public
may not be able to defaults to/
. (Because ofdevServer.public
having higher priority thanbaseUrl
).But I would vote yes to make
devServer.public
accept relative urls.da38ed4
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.
@jkzing I guess what I am trying to say is the sockjs url can also be relative, and that's exactly what Gatsbyjs did.
I think a while ago it was required to be absolute but it seems to work in every possible case we have tried (see full list under Gatsby's PR).
Because the code runs in the browser and the browser will always automatically default to using the correct name of the "public dns" you accessed the page from if the default is a relative path?
I see that point but if we let the browser decide on the base path (domain / port / protocol) it would solve that problem as well (same exact issue that Gatsby had)
da38ed4
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.
In that example, the custom configuration doesn't actually make sense as I previously stated (they might have only done this because it didn't work with defaults? (that's my assumption)).
The assumption here is that the
--host
param can be used as a URL, IP address binding should not be the same configuration as public url's .da38ed4
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.
@drubin
I didn't find the cases you said in the PR. But even if it works in
Gatsby
, it doesn't mean also works in vue CLI. (Gatsby
is usingwebpack-hot-middleware/client
and vue CLI is usingwebpack-dev-server/client
, they are different implementations.)No, at least with
webpack-dev-server/client
it can not. See howwebpack-dev-server/client
do this here: https://github.com/webpack/webpack-dev-server/blob/fadae5da6ba0261cade08164feeaad99b1de6b79/client-src/default/index.js#L30This can be turned to "Whether accessing index.html from a host other than the one dev-server uses makes sense". From my experience, it makes sense.
If you still think it's a better idea to default to relative path, let's open an issue and discuss it there.😊