Skip to content

Commit 8363773

Browse files
committed
only emit wasm runtime code for bundles containing wasm
1 parent 5840039 commit 8363773

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Chunk.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,24 @@ class Chunk {
579579
};
580580
}
581581

582+
hasModuleInGraph(filterFn) {
583+
const chunksProcessed = new Set();
584+
const queue = [this];
585+
586+
while(queue.length > 0) {
587+
const chunk = queue.pop();
588+
if(chunk.getModules().some(filterFn))
589+
return true;
590+
for(const next of chunk.chunksIterable) {
591+
if(!chunksProcessed.has(next)) {
592+
chunksProcessed.add(next);
593+
queue.push(next);
594+
}
595+
}
596+
}
597+
return false;
598+
}
599+
582600
sortModules(sortByFn) {
583601
this._modules.sortWith(sortByFn || sortById);
584602
}

lib/web/FetchCompileWasmMainTemplatePlugin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class FetchCompileWasmMainTemplatePlugin {
88

99
apply(mainTemplate) {
1010
mainTemplate.plugin("local-vars", (source, chunk) => {
11+
if(!chunk.hasModuleInGraph(m => m.type.startsWith("webassembly")))
12+
return source;
1113
return mainTemplate.asString([
1214
source,
1315
"",
@@ -69,6 +71,8 @@ class FetchCompileWasmMainTemplatePlugin {
6971
]);
7072
});
7173
mainTemplate.plugin("require-extensions", (source, chunk) => {
74+
if(!chunk.hasModuleInGraph(m => m.type.startsWith("webassembly")))
75+
return source;
7276
return mainTemplate.asString([
7377
source,
7478
"",

0 commit comments

Comments
 (0)