feat: run webpack-dev-server as a compiler plugin - #4847
Conversation
🦋 Changeset detectedLatest commit: 9d25338 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
This PR is packaged and the instant preview is available (9d25338). Install it locally:
npm i -D webpack-cli@https://pkg.pr.new/webpack-cli@9d25338
yarn add -D webpack-cli@https://pkg.pr.new/webpack-cli@9d25338
pnpm add -D webpack-cli@https://pkg.pr.new/webpack-cli@9d25338 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
Big pr, gonna review in depth this weekend |
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 existingstart()/stop()flow.The plugin path disables the server's own signal handlers to avoid duplicate shutdown and preserves failure exit codes. Duplicate ports in
devServerconfigurations 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:
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: trueis 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.