From cc86e83fb90ebfa157ac696f8efebebe0e1f0ce4 Mon Sep 17 00:00:00 2001 From: Albert Salazar Date: Mon, 28 Jun 2021 19:32:54 -0700 Subject: [PATCH 1/2] Move assets check later to actual hook process. --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a8e925b..b8792a3 100644 --- a/index.js +++ b/index.js @@ -13,8 +13,10 @@ module.exports = class PostCSSAssetsPlugin { this.log = log ? fancyLog : () => {}; } - run(compilation) { - const { assets } = compilation; + run(assets) { + if (!(Object.keys(assets).length > 0)) { + return Promise.resolve(); + } this.log('PostCSSAssetsPlugin: Starting...'); @@ -94,10 +96,12 @@ module.exports = class PostCSSAssetsPlugin { if (stage) { compiler.hooks.compilation.tap(pluginName, (compilation) => { const stageSettings = { name: pluginName, stage }; - compilation.hooks.processAssets.tapPromise(stageSettings, () => this.run(compilation)); + compilation.hooks.processAssets.tapPromise(stageSettings, (assets) => { + return this.run(assets || compilation.assets); + }); }); } else { - compiler.hooks.emit.tapPromise(pluginName, (compilation) => this.run(compilation)); + compiler.hooks.emit.tapPromise(pluginName, ({assets}) => this.run(assets)); } } }; From 2a44bab27fb97a508a59140c8cb3cbf037184d08 Mon Sep 17 00:00:00 2001 From: Albert Salazar Date: Tue, 29 Jun 2021 09:52:34 -0700 Subject: [PATCH 2/2] Use strict count check. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b8792a3..63ad61f 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ module.exports = class PostCSSAssetsPlugin { } run(assets) { - if (!(Object.keys(assets).length > 0)) { + if (Object.keys(assets).length === 0) { return Promise.resolve(); }