Skip to content

Commit

Permalink
Merge pull request #6 from chibibirdie/check-for-assets-fix
Browse files Browse the repository at this point in the history
Move assets check later to actual hook process.
  • Loading branch information
klimashkin authored Jul 14, 2021
2 parents 90abaaf + bf3cca6 commit f28ef0e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...');

Expand Down Expand Up @@ -93,13 +95,13 @@ module.exports = class PostCSSAssetsPlugin {

if (stage) {
compiler.hooks.compilation.tap(pluginName, (compilation) => {
if (Object.keys(compilation.assets).length) {
const stageSettings = { name: pluginName, stage };
compilation.hooks.processAssets.tapPromise(stageSettings, () => this.run(compilation));
}
const stageSettings = { name: pluginName, stage };
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));
}
}
};

0 comments on commit f28ef0e

Please sign in to comment.