Skip to content

Allow same devServer port with unique publicPath#4701

Open
MITHRAN-BALACHANDER wants to merge 2 commits intowebpack:mainfrom
MITHRAN-BALACHANDER:serve-with-multiserve
Open

Allow same devServer port with unique publicPath#4701
MITHRAN-BALACHANDER wants to merge 2 commits intowebpack:mainfrom
MITHRAN-BALACHANDER:serve-with-multiserve

Conversation

@MITHRAN-BALACHANDER
Copy link

fix(serve): allow shared devServer port when publicPath values are unique

Summary

This PR fixes a serve regression in multi-compiler mode where webpack-cli rejected any repeated devServer port, even when each compiler exposed a different app path.

The serve startup logic now allows multiple devServer configs to share the same port only when each config has a unique public path (resolved from devServer.devMiddleware.publicPath or output.publicPath). If the same port is reused without a unique path, webpack-cli still throws an error.

Changes included:

  • Add per-port publicPath tracking using usedPublicPathsByPort.
  • Refine the conflict error message to explain the unique-publicPath requirement for shared ports.
  • Add a regression fixture: same-ports-dev-server-unique-public-paths.config.js.
  • Add a regression test case in serve basic tests.
  • Update snapshots for both conflict and success scenarios.

Motivation:

  • Multi-SPA local development often serves multiple apps from one dev server port while separating them by route prefix (for example /login/ and /admin/). This PR restores that valid workflow.

What kind of change does this PR introduce?

fix + test

Did you add tests for your changes?

Yes.

Added/updated tests cover:

  • Same port + conflicting/missing public paths: still errors.
  • Same port + unique public paths: now allowed.

Snapshots were updated accordingly.

Does this PR introduce a breaking change?

No.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

No docs updates are required. This aligns runtime behavior with expected webpack-dev-server multi-compiler usage patterns.

Use of AI

AI assistance was used to help draft and iterate on the implementation and tests. All AI-suggested changes were manually reviewed, edited, and validated with linting and test runs before submission.

Permit multiple devServer configs to share the same port when each config exposes a unique devMiddleware.publicPath or output.publicPath. Introduces usedPublicPathsByPort tracking and refines the error message to instruct using unique publicPath values for shared ports. Adds a test config (same-ports-dev-server-unique-public-paths.config.js), a test case and snapshot updates to cover the new behavior, and adds webpack-cli to package.json dependencies.
@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2026

⚠️ No Changeset found

Latest commit: 82922e5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 16, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant