From 85e2fd39fde425f7b73cb87b0cbcdde338cccb00 Mon Sep 17 00:00:00 2001 From: adryd Date: Thu, 23 Nov 2023 09:38:58 -0500 Subject: [PATCH] webpack 4 fixes --- .gitignore | 4 +++- src/patcher.js | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8af3b6b..e3dac05 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -dist/webpackToolsRuntime.js +dist/webpackTools.user.js +dist/webpackTools.runtime.js +dist/webpackTools.runtime.json node_modules \ No newline at end of file diff --git a/src/patcher.js b/src/patcher.js index 766fc26..a5bfa45 100644 --- a/src/patcher.js +++ b/src/patcher.js @@ -151,7 +151,18 @@ function injectModules(chunk) { } } + // Convert array to object for named modules + if (chunk[1] instanceof Array) { + const origChunkArray = chunk[1]; + chunk[1] = {}; + origChunkArray.forEach((module, index) => { + chunk[1][index] = module; + }); + } + + // merge our modules with original modules chunk[1] = Object.assign(chunk[1], injectModules); + if (injectEntries.length > 0) { switch (config.webpackVersion) { case "5": @@ -168,9 +179,14 @@ function injectModules(chunk) { } break; case "4": - chunk[2] = (chunk[2] ?? []).concat(injectEntries); + if (chunk[2]?.[0]) { + chunk[2]?.[0].concat([injectEntries]); + } else { + chunk[2] = [injectEntries]; + } break; } } + console.log(chunk); } }