Skip to content

Commit

Permalink
Defer logging of outputs by a tick to ensure its the last thing on th…
Browse files Browse the repository at this point in the history
…e screen
  • Loading branch information
developit committed Mar 15, 2019
1 parent 0749560 commit 0191975
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ export default class SizePlugin {
const outputPath = compiler.options.output.path;
this.output = compiler.options.output;
this.sizes = this.getSizes(outputPath);
const afterEmit = (compilation, callback) => {
process.nextTick(() => {
this.outputSizes(compilation.assets).catch(console.error);
callback();
});
};
// for webpack version > 4
if (compiler.hooks && compiler.hooks.afterEmit) {
return compiler.hooks.afterEmit.tapPromise(NAME, compilation =>
this.outputSizes(compilation.assets).catch(console.error)
);
return compiler.hooks.afterEmit.tapAsync(NAME, afterEmit);
}
// for webpack version < 3
return compiler.plugin('after-emit', (compilation, callback) => {
this.outputSizes(compilation.assets)
.catch(console.error)
.then(callback);
});
return compiler.plugin('after-emit', afterEmit);
}

async outputSizes (assets) {
Expand Down
10 changes: 6 additions & 4 deletions test/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export function compile(entry, configDecorator) {
config = configDecorator(config) || config;
}
webpack(config, (err, stats) => {
if (err) return reject(err);
const info = stats.toJson();
if (stats.hasErrors()) return reject(info.errors.join('\n'));
resolve(info);
setTimeout(() => {
if (err) return reject(err);
const info = stats.toJson();
if (stats.hasErrors()) return reject(info.errors.join('\n'));
resolve(info);
}, 10);
});
});
}

0 comments on commit 0191975

Please sign in to comment.