Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8fd601f
fix: clean the files writeToDisk writes when output.clean is set
alexander-akait Oct 27, 2026
52bed0b
chore: keep the standalone-mode TODO out of the published types
alexander-akait Oct 27, 2026
d5c16a9
fix: write to disk with writeToDisk true and a custom outputFileSystem
alexander-akait Oct 27, 2026
a2a28e9
test: list the output without Dirent#parentPath
alexander-akait Oct 27, 2026
c0fe374
test: cover copy-webpack-plugin with writeToDisk and output.clean
alexander-akait Oct 27, 2026
904f558
fix: skip disk cleaning for compilers without webpack's CleanPlugin
alexander-akait Oct 27, 2026
05e2215
fix: clean disk copies the writeToDisk function skips
alexander-akait Oct 27, 2026
f56170b
fix: clean disk copies of assets named with a query string
alexander-akait Oct 27, 2026
8ad3c99
test: wait for the build after the change in write-to-disk clean tests
alexander-akait Oct 27, 2026
5ff497e
refactor: write to disk through webpack's additionalOutputs hook
alexander-akait Oct 27, 2026
b38df13
test: cover the disk added through additionalOutputs on any webpack
alexander-akait Oct 27, 2026
9dd4ab0
fix: clean writeToDisk files through a two-way output file system
alexander-akait Nov 13, 2026
8d364c2
test: wait for the rebuild through watchRun instead of startTime
alexander-akait Nov 13, 2026
06b38b5
fix: handle file systems of your own when writing to disk
alexander-akait Nov 13, 2026
7741eba
test: list the in-memory files one directory at a time
alexander-akait Nov 13, 2026
480eafa
test: cover every path of the file system writing to disk
alexander-akait Nov 13, 2026
c99f8f9
refactor: simplify the file system writing to disk
alexander-akait Nov 20, 2026
8709d95
docs: note how to replace the disk-writing file system in the next major
alexander-akait Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/write-to-disk-output-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webpack-dev-middleware": patch
---

Clean the files `writeToDisk` writes when `output.clean` is set. webpack wrote the build to memory and cleaned only that, so the copies on disk were never cleaned: the previous session's files stayed, and every rebuild left another `main.[contenthash].js` behind. The middleware now gives webpack a file system that writes to memory and, for the files `writeToDisk` takes, to disk, and that removes and lists files on both, so `output.clean` cleans the disk too, honoring `clean.keep` and `clean.dry`, in plugin mode as in standalone mode, with every webpack 5 version and with Rspack. `writeToDisk: true` with a file system of your own, in `outputFileSystem` or on the compiler, now writes to disk too: it wrote nothing there before.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"valuenow",
"webworker",
"wildcarded",
"Fapp"
"Fapp",
"gracefulify"
],
"ignorePaths": [
"CHANGELOG.md",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,15 @@ middleware(compiler, {
});
```

With either value, [`output.clean`](https://webpack.js.org/configuration/output/#outputclean) cleans the files on disk as it cleans webpack's output: the directory on the first build, the files a rebuild no longer emits after that, with `clean.keep` and `clean.dry` honored. The files the function leaves out stay off disk, and a copy of one left there by an earlier session is removed. Links, permissions and times are written to disk as webpack writes them. With a file system of your own, given in `outputFileSystem` or set on the compiler, the files are written to it and to disk, and both are cleaned; one lacking methods webpack does without, such as `symlink`, works too. This works with every webpack 5 version and with Rspack. An asset named with a query string, such as `[name].js?[contenthash]`, is left on disk once it is gone, as it is without the middleware, until webpack's `output.clean` matches such a name to its file.

### outputFileSystem

Type: `Object`
Default: [memfs](https://github.com/streamich/memfs)

Set the default file system which will be used by webpack as primary destination of generated files.
This option isn't affected by the [writeToDisk](#writeToDisk) option.
This option isn't affected by the [writeToDisk](#writetodisk) option. With `writeToDisk` set, files are written to it as before and also to disk — with `true` as with a function.

You have to provide `.join()` and `mkdirp` method to the `outputFileSystem` instance manually for compatibility with `webpack@4`.

Expand Down
48 changes: 48 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"babel-loader": "^10.1.1",
"babel-plugin-istanbul": "^8.0.0",
"connect": "^3.7.0",
"copy-webpack-plugin": "^14.0.0",
"cspell": "^10.2.0",
"deepmerge": "^4.3.1",
"del-cli": "^8.0.1",
Expand Down
Loading
Loading