From a91478f3fe10c895058785869f547d17c2fe9dd6 Mon Sep 17 00:00:00 2001 From: Jeremy John Date: Mon, 13 Jul 2020 10:33:47 -0500 Subject: [PATCH] fix: support compiler hooks like afterCompile where stats.toJson is undefined --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index fae1266..a929f64 100644 --- a/index.js +++ b/index.js @@ -41,8 +41,8 @@ WebpackCopyOnPlugin.prototype.apply = function(compiler) { }; compiler.plugin(eventHook, function(stats) { - const statsJson = stats.toJson(); - const chunks = statsJson.chunks; + const statsJson = stats.toJson ? stats.toJson() : {}; + const chunks = statsJson.chunks ? statsJson.chunks : []; chunks.forEach(function(chunk) { const chunkName = chunk.names[0]; let mapping = mappings[chunkName];