From d60c640eb7eaf0673a4930fc9cf7777b89a2c0ab Mon Sep 17 00:00:00 2001 From: Ice Lam Date: Fri, 22 Jan 2021 19:53:45 +0800 Subject: [PATCH] fix: assets source become undefined in some scenario Related to issue #1, where multiple instances of html-webpack-plugin is used --- src/HtmlInlineScriptPlugin.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/HtmlInlineScriptPlugin.ts b/src/HtmlInlineScriptPlugin.ts index c30ea76..0496ceb 100644 --- a/src/HtmlInlineScriptPlugin.ts +++ b/src/HtmlInlineScriptPlugin.ts @@ -64,14 +64,13 @@ class HtmlInlineScriptPlugin { ); return data; }); + }); - hooks.beforeEmit.tap(`${PLUGIN_PREFIX}_beforeEmit`, (data) => { - Object.keys(compilation.assets).forEach((assetName) => { - if (this.isFileNeedsToBeInlined(assetName)) { - delete compilation.assets[assetName]; - } - }); - return data; + compiler.hooks.emit.tap(`${PLUGIN_PREFIX}_emit`, (compilation) => { + Object.keys(compilation.assets).forEach((assetName) => { + if (this.isFileNeedsToBeInlined(assetName)) { + delete compilation.assets[assetName]; + } }); }); }