Skip to content

Commit

Permalink
webpack 4 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adryd325 committed Nov 23, 2023
1 parent 2b5cb55 commit 85e2fd3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
dist/webpackToolsRuntime.js
dist/webpackTools.user.js
dist/webpackTools.runtime.js
dist/webpackTools.runtime.json
node_modules
18 changes: 17 additions & 1 deletion src/patcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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);
}
}

0 comments on commit 85e2fd3

Please sign in to comment.