Skip to content

Instantly share code, notes, and snippets.

@rowanoulton
Created January 16, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowanoulton/c092b27d7c8cf0c225beaabad5fd11d1 to your computer and use it in GitHub Desktop.
Save rowanoulton/c092b27d7c8cf0c225beaabad5fd11d1 to your computer and use it in GitHub Desktop.
A webpack plugin that crudely measures the execution time of UglifyJSPlugin
let CrudeTimingPlugin = function() {};
CrudeTimingPlugin.prototype.apply = function(compiler) {
compiler.plugin('compilation', (compilation) => {
let startOptimizePhase;
compilation.plugin('optimize-chunk-assets', (chunks, callback) => {
// Cruddy way of measuring minification time. UglifyJSPlugin does all
// its work in this phase of compilation so we time the duration of
// the entire phase
startOptimizePhase = Date.now();
// For async phases: don't forget to invoke the callback
callback();
});
compilation.plugin('after-optimize-chunk-assets', () => {
const optimizePhaseDuration = Date.now() - startOptimizePhase;
console.log(`optimize-chunk-asset phase duration: ${optimizePhaseDuration}`);
});
});
};
module.exports = CrudeTimingPlugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment