mirror of
https://github.com/flarum/core.git
synced 2025-08-04 15:37:51 +02:00
fix: code splitting on dev mode
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const extensionId = require('./extensionId.cjs');
|
const extensionId = require('./extensionId.cjs');
|
||||||
const { Compilation } = require('webpack');
|
const { Compilation } = require('webpack');
|
||||||
|
const ConcatenatedModule = require('webpack/lib/optimize/ConcatenatedModule');
|
||||||
|
|
||||||
class RegisterAsyncChunksPlugin {
|
class RegisterAsyncChunksPlugin {
|
||||||
static registry = {};
|
static registry = {};
|
||||||
@@ -81,14 +82,40 @@ class RegisterAsyncChunksPlugin {
|
|||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
let concatenatedModule = chunkModules(relevantChunk)[0];
|
const relevantChunkModules = chunkModules(relevantChunk);
|
||||||
const moduleId = compilation.chunkGraph.getModuleId(concatenatedModule);
|
const mainModule = relevantChunkModules.filter((m) => {
|
||||||
|
return m.resource?.split('.')[0] === importPathResolved || m.rootModule?.resource?.split('.')[0] === importPathResolved;
|
||||||
|
})[0];
|
||||||
|
const otherRelevantChunkModules = relevantChunkModules.filter((m) => m !== mainModule);
|
||||||
|
|
||||||
|
if (mainModule instanceof ConcatenatedModule && mainModule.modules) {
|
||||||
|
otherRelevantChunkModules.push(...mainModule.modules);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mainModule) {
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
const moduleId = compilation.chunkGraph.getModuleId(mainModule);
|
||||||
const registrableModulesUrlPaths = new Map();
|
const registrableModulesUrlPaths = new Map();
|
||||||
registrableModulesUrlPaths.set(urlPath, [relevantChunk.id, moduleId, namespace, urlPath]);
|
registrableModulesUrlPaths.set(urlPath, [relevantChunk.id, moduleId, namespace, urlPath]);
|
||||||
|
|
||||||
if (concatenatedModule?.rootModule) {
|
const modules = [];
|
||||||
|
|
||||||
|
otherRelevantChunkModules.forEach((module) => {
|
||||||
|
if (module instanceof ConcatenatedModule && module.modules) {
|
||||||
|
modules.push(...module.modules);
|
||||||
|
} else {
|
||||||
|
modules.push(module);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (relevantChunk.name.endsWith('PostStream')) {
|
||||||
|
console.log(otherRelevantChunkModules);
|
||||||
|
}
|
||||||
|
|
||||||
// This is a chunk with many modules, we need to register all of them.
|
// This is a chunk with many modules, we need to register all of them.
|
||||||
concatenatedModule.modules?.forEach((module) => {
|
modules?.forEach((module) => {
|
||||||
if (!module.resource.includes(`${path.sep}src${path.sep}`)) {
|
if (!module.resource.includes(`${path.sep}src${path.sep}`)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -101,7 +128,6 @@ class RegisterAsyncChunksPlugin {
|
|||||||
registrableModulesUrlPaths.set(urlPath, [relevantChunk.id, moduleId, namespace, urlPath]);
|
registrableModulesUrlPaths.set(urlPath, [relevantChunk.id, moduleId, namespace, urlPath]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
registrableModulesUrlPaths.forEach(([chunkId, moduleId, namespace, urlPath]) => {
|
registrableModulesUrlPaths.forEach(([chunkId, moduleId, namespace, urlPath]) => {
|
||||||
chunkModuleMemory[sourceChunkId] = chunkModuleMemory[sourceChunkId] || [];
|
chunkModuleMemory[sourceChunkId] = chunkModuleMemory[sourceChunkId] || [];
|
||||||
|
Reference in New Issue
Block a user