Skip to content

Commit 063b95a

Browse files
authored
Merge pull request #54 from chenjiahan/enhance-writeToDisk
feat: support filter writeToDisk by compilation name
2 parents ef2c70b + dabdba8 commit 063b95a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const noop = () => {};
100100
* @template {IncomingMessage} [RequestInternal = IncomingMessage]
101101
* @template {ServerResponse} [ResponseInternal = ServerResponse]
102102
* @typedef {Object} Options
103-
* @property {boolean | ((targetPath: string) => boolean)} [writeToDisk]
103+
* @property {boolean | ((targetPath: string, compilationName?: string) => boolean)} [writeToDisk]
104104
* @property {NonNullable<Configuration["output"]>["publicPath"]} [publicPath]
105105
* @property {boolean | string} [index]
106106
* @property {boolean} [lastModified]

src/utils/setupWriteToDisk.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ function setupWriteToDisk(context) {
2929

3030
compiler.hooks.assetEmitted.tapAsync(
3131
"DevMiddleware",
32-
(file, info, callback) => {
33-
const { targetPath, content } = info;
32+
(_file, info, callback) => {
33+
const { targetPath, content, compilation } = info;
3434
const { writeToDisk: filter } = context.options;
3535
const allowWrite =
36-
filter && typeof filter === "function" ? filter(targetPath) : true;
36+
filter && typeof filter === "function"
37+
? filter(targetPath, compilation.name)
38+
: true;
3739

3840
if (!allowWrite) {
3941
return callback();

types/index.d.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export = wdm;
7575
* @template {IncomingMessage} [RequestInternal = IncomingMessage]
7676
* @template {ServerResponse} [ResponseInternal = ServerResponse]
7777
* @typedef {Object} Options
78-
* @property {boolean | ((targetPath: string) => boolean)} [writeToDisk]
78+
* @property {boolean | ((targetPath: string, compilationName?: string) => boolean)} [writeToDisk]
7979
* @property {NonNullable<Configuration["output"]>["publicPath"]} [publicPath]
8080
* @property {boolean | string} [index]
8181
* @property {boolean} [lastModified]
@@ -256,7 +256,10 @@ type Options<
256256
RequestInternal extends IncomingMessage = import("http").IncomingMessage,
257257
ResponseInternal extends ServerResponse = ServerResponse,
258258
> = {
259-
writeToDisk?: boolean | ((targetPath: string) => boolean) | undefined;
259+
writeToDisk?:
260+
| boolean
261+
| ((targetPath: string, compilationName?: string) => boolean)
262+
| undefined;
260263
publicPath?: NonNullable<Configuration["output"]>["publicPath"];
261264
index?: string | boolean | undefined;
262265
lastModified?: boolean | undefined;

0 commit comments

Comments
 (0)