Skip to content

Ability to load hmr end-point address from vite.config #676

@sionzee

Description

@sionzee

Is your feature request related to a problem? Please describe.
The vite is using location.hostname to resolve location of the page:

const socketUrl = `${socketProtocol}://${location.hostname}:${__PORT__}`

Which results in issue when people are using custom forwarding with specific port or doing other similar stuff.

We would like to have property at config where is "hmr" for client located.
eg.:

hmr: {
  hostname: "localhost"
}

In our case we are using vite as Library and vite should be restricted to localhost only. Where location.hostname is the forwarded url which has no the hmr port enabled.

Describe the solution you'd like
Vite should support custom url for hmr or be more connected to hostname property at ServerConfig.

Additional context
WSL have many issues around port-forwarding. So the root of the page is running on whatever:port and vite is located at localhost:port. When whatever:port is visited then vite's hmr is trying to open whatever:hmrport, even when vite-hmr + client-code are loaded from localhost:port.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions