Skip to content

feat: add ability to set HMR port#27326

Merged
danielroe merged 5 commits intonuxt:mainfrom
samupl:feat/change-hmr-port
May 28, 2024
Merged

feat: add ability to set HMR port#27326
danielroe merged 5 commits intonuxt:mainfrom
samupl:feat/change-hmr-port

Conversation

@samupl
Copy link
Copy Markdown
Contributor

@samupl samupl commented May 23, 2024

🔗 Linked issue

resolves #27325

📚 Description

Adds an ability to set the HMR port by setting vite.server.hmr.port in nuxt.config.ts. This solves the problem of running HMR on environments with firewalls and/or limited port range assigned to user(s).

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions Bot added the 3.x label May 23, 2024
@samupl samupl changed the title Feat: add ability to set HMR port feat: add ability to set HMR port May 23, 2024
@danielroe
Copy link
Copy Markdown
Member

danielroe commented May 23, 2024

I think the Vite port is being overridden here to be the same as the Nuxt default port:

https://github.com/nuxt/cli/blob/998634212df0a564a6c5ba1ddbe40d5870a74d77/src/utils/dev.ts#L189-L208

cc: @pi0

@danielroe danielroe requested a review from pi0 May 24, 2024 08:13
@samupl
Copy link
Copy Markdown
Contributor Author

samupl commented May 24, 2024

@danielroe You seem to be right. However it seems that packages/vite/src/client.ts in this repo is still attempting to bind to a port beforehand, and this is failing on environments with limited permissions to bind to ports.

I can try to follow up with a PR to @nuxt/cli repo as well and try to fix that, but it seems that this PR might still be required.

In the meantime I fixed some typing issues and ensured that it first attempts to bind to the port in the config.

@danielroe
Copy link
Copy Markdown
Member

danielroe commented May 28, 2024

Opened a PR to nuxt/cli - we can then update this PR to check if clientConfig.server.hmr.server is set and if so, avoid calling getPort as it will be unneeded.

I would also avoid changing the schema in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to configure HMR port

3 participants