diff --git a/src/index.js b/src/index.js index b9d85cd..de24ab6 100644 --- a/src/index.js +++ b/src/index.js @@ -100,7 +100,7 @@ const noop = () => {}; * @template {IncomingMessage} [RequestInternal = IncomingMessage] * @template {ServerResponse} [ResponseInternal = ServerResponse] * @typedef {Object} Options - * @property {boolean | ((targetPath: string) => boolean)} [writeToDisk] + * @property {boolean | ((targetPath: string, compilationName?: string) => boolean)} [writeToDisk] * @property {NonNullable["publicPath"]} [publicPath] * @property {boolean | string} [index] * @property {boolean} [lastModified] diff --git a/src/utils/setupWriteToDisk.js b/src/utils/setupWriteToDisk.js index e70becf..b4b6c60 100644 --- a/src/utils/setupWriteToDisk.js +++ b/src/utils/setupWriteToDisk.js @@ -29,11 +29,13 @@ function setupWriteToDisk(context) { compiler.hooks.assetEmitted.tapAsync( "DevMiddleware", - (file, info, callback) => { - const { targetPath, content } = info; + (_file, info, callback) => { + const { targetPath, content, compilation } = info; const { writeToDisk: filter } = context.options; const allowWrite = - filter && typeof filter === "function" ? filter(targetPath) : true; + filter && typeof filter === "function" + ? filter(targetPath, compilation.name) + : true; if (!allowWrite) { return callback(); diff --git a/types/index.d.ts b/types/index.d.ts index ad7c127..f79640e 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -75,7 +75,7 @@ export = wdm; * @template {IncomingMessage} [RequestInternal = IncomingMessage] * @template {ServerResponse} [ResponseInternal = ServerResponse] * @typedef {Object} Options - * @property {boolean | ((targetPath: string) => boolean)} [writeToDisk] + * @property {boolean | ((targetPath: string, compilationName?: string) => boolean)} [writeToDisk] * @property {NonNullable["publicPath"]} [publicPath] * @property {boolean | string} [index] * @property {boolean} [lastModified] @@ -256,7 +256,10 @@ type Options< RequestInternal extends IncomingMessage = import("http").IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse, > = { - writeToDisk?: boolean | ((targetPath: string) => boolean) | undefined; + writeToDisk?: + | boolean + | ((targetPath: string, compilationName?: string) => boolean) + | undefined; publicPath?: NonNullable["publicPath"]; index?: string | boolean | undefined; lastModified?: boolean | undefined;