Skip to content

feat: run webpack-dev-server as a compiler plugin - #4847

Open
bjohansebas wants to merge 5 commits into
mainfrom
feat/dev-server-plugin-support
Open

feat: run webpack-dev-server as a compiler plugin#4847
bjohansebas wants to merge 5 commits into
mainfrom
feat/dev-server-plugin-support

Conversation

@bjohansebas

Copy link
Copy Markdown
Member

Summary

Run webpack-dev-server as a compiler plugin when it exposes apply(). The CLI starts watch compilation, prints build stats, and closes the compiler on signals or stdin EOF so the server stops through its shutdown hooks. Older dev servers keep their existing start()/stop() flow.

The plugin path disables the server's own signal handlers to avoid duplicate shutdown and preserves failure exit codes. Duplicate ports in devServer configurations are detected before listening starts.

Known limitation: webpack-dev-server currently logs errors from the plugin's asynchronous listen() phase without propagating them to the CLI. That requires a follow-up in webpack-dev-server; setup errors reaching the watch callback exit with code 2.

What kind of change does this PR introduce?

Feature, with shutdown fixes and regression tests.

Did you add tests for your changes?

Yes. Tests cover compilation errors and warnings, middleware setup failures, exit status and shutdown through SIGINT/SIGTERM/stdin, duplicate signal handlers, serving rebuilt bundles, and independent multi-compiler rebuilds with distinct watch options and shutdown hooks. The duplicate-port snapshot is updated for validation before startup.

Validation with webpack-dev-server 6:

  • Build, ESLint, Prettier and CSpell passed.
  • 5 suites passed: 64 tests passed, 1 skipped, and 32 snapshots passed.
npm run test:base -- test/serve/error-handling test/serve/rebuild test/serve/basic test/watch/stdin test/watch/basic --runInBand --roots test/serve test/watch

Does this PR introduce a breaking change?

No intended breaking change. Existing webpack-dev-server 5 integration remains on the imperative path. In plugin mode, the CLI owns signal handling even when setupExitSignals: true is configured, and shutdown preserves compilation failure status.

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

Added a minor changeset describing compiler plugin support. The serve documentation should explain CLI ownership of watch compilation, stats output, and shutdown with webpack-dev-server 6.

Use of AI

Codex assisted with implementation, regression tests, code review, and this PR description. The changes were developed interactively with contributor feedback, and the validation results above were checked during that process.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9d25338

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-cli Minor

Not sure what this means? Click here to learn what changesets are.

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

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (9d25338).

Install it locally:

  • npm
npm i -D webpack-cli@https://pkg.pr.new/webpack-cli@9d25338
  • yarn
yarn add -D webpack-cli@https://pkg.pr.new/webpack-cli@9d25338
  • pnpm
pnpm add -D webpack-cli@https://pkg.pr.new/webpack-cli@9d25338

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.76536% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.92%. Comparing base (cdb841d) to head (9d25338).

Files with missing lines Patch % Lines
packages/webpack-cli/src/webpack-cli.ts 97.76% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4847      +/-   ##
==========================================
+ Coverage   94.81%   94.92%   +0.10%     
==========================================
  Files          14       14              
  Lines        5598     5737     +139     
  Branches      837      878      +41     
==========================================
+ Hits         5308     5446     +138     
- Misses        289      290       +1     
  Partials        1        1              
Files with missing lines Coverage Δ
packages/webpack-cli/src/webpack-cli.ts 96.79% <97.76%> (+0.09%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cdb841d...9d25338. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@evenstensberg

Copy link
Copy Markdown
Member

Big pr, gonna review in depth this weekend

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.

2 participants