From 445d5483568f03e3cdcd0f5cd3255de361882ea3 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Thu, 1 Mar 2018 23:50:02 +0300 Subject: [PATCH] fix(index): `tapable` deprecation warnings (`webpack >= v4.0.0`) (#234) --- src/index.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index a59af22f..27cf1bea 100644 --- a/src/index.js +++ b/src/index.js @@ -55,7 +55,7 @@ function CopyWebpackPlugin(patterns = [], options = {}) { context = options.context; } - compiler.plugin('emit', (compilation, cb) => { + const emit = (compilation, cb) => { debug('starting emit'); const callback = () => { debug('finishing emit'); @@ -103,9 +103,9 @@ function CopyWebpackPlugin(patterns = [], options = {}) { compilation.errors.push(err); }) .then(() => callback()); - }); + }; - compiler.plugin('after-emit', (compilation, cb) => { + const afterEmit = (compilation, cb) => { debug('starting after-emit'); const callback = () => { debug('finishing after-emit'); @@ -153,7 +153,17 @@ function CopyWebpackPlugin(patterns = [], options = {}) { } callback(); - }); + }; + + if (compiler.hooks) { + const plugin = { name: 'CopyPlugin' }; + + compiler.hooks.emit.tapAsync(plugin, emit); + compiler.hooks.afterEmit.tapAsync(plugin, afterEmit); + } else { + compiler.plugin('emit', emit); + compiler.plugin('after-emit', afterEmit); + } }; return {