perf(webui): lazily load module descriptors
This commit is contained in:
@@ -9,6 +9,8 @@ const require = createRequire(import.meta.url);
|
||||
const webuiRoot = dirname(fileURLToPath(import.meta.url));
|
||||
const installedModulesVirtualId = "virtual:govoplan-installed-modules";
|
||||
const resolvedInstalledModulesVirtualId = `\0${installedModulesVirtualId}`;
|
||||
const installedModuleVirtualPrefix = "virtual:govoplan-installed-module/";
|
||||
const resolvedInstalledModuleVirtualPrefix = `\0${installedModuleVirtualPrefix}`;
|
||||
|
||||
const defaultWebModulePackages = [
|
||||
"@govoplan/access-webui",
|
||||
@@ -31,6 +33,7 @@ const defaultWebModulePackages = [
|
||||
"@govoplan/postbox-webui",
|
||||
"@govoplan/risk-compliance-webui",
|
||||
"@govoplan/scheduling-webui",
|
||||
"@govoplan/search-webui",
|
||||
"@govoplan/views-webui",
|
||||
"@govoplan/workflow-webui"
|
||||
];
|
||||
@@ -61,20 +64,41 @@ function availableWebModuleSpecifiers(): string[] {
|
||||
}
|
||||
|
||||
function govoplanInstalledModulesPlugin(): Plugin {
|
||||
const specifierByModuleVirtualId = new Map(
|
||||
availableWebModuleSpecifiers().map((specifier) => [
|
||||
`${installedModuleVirtualPrefix}${encodeURIComponent(specifier)}`,
|
||||
specifier
|
||||
])
|
||||
);
|
||||
|
||||
return {
|
||||
name: "govoplan-installed-modules",
|
||||
resolveId(id: string) {
|
||||
if (id === installedModulesVirtualId) return resolvedInstalledModulesVirtualId;
|
||||
if (specifierByModuleVirtualId.has(id)) return `\0${id}`;
|
||||
return null;
|
||||
},
|
||||
load(id: string) {
|
||||
if (id !== resolvedInstalledModulesVirtualId) return null;
|
||||
const imports = availableWebModuleSpecifiers();
|
||||
return [
|
||||
...imports.map((specifier, index) => `import module${index} from ${JSON.stringify(specifier)};`),
|
||||
`export const installedWebModules = [${imports.map((_specifier, index) => `module${index}`).join(", ")}];`,
|
||||
"export default installedWebModules;"
|
||||
].join("\n");
|
||||
if (id === resolvedInstalledModulesVirtualId) {
|
||||
const loaders = [...specifierByModuleVirtualId].map(([virtualId, specifier]) => (
|
||||
`{ packageName: ${JSON.stringify(specifier)}, load: () => import(${JSON.stringify(virtualId)}) }`
|
||||
));
|
||||
return [
|
||||
`export const installedWebModuleLoaders = [${loaders.join(", ")}];`,
|
||||
"export default installedWebModuleLoaders;"
|
||||
].join("\n");
|
||||
}
|
||||
if (!id.startsWith(resolvedInstalledModuleVirtualPrefix)) return null;
|
||||
const publicVirtualId = id.slice(1);
|
||||
const specifier = specifierByModuleVirtualId.get(publicVirtualId);
|
||||
if (!specifier) return null;
|
||||
const moduleEntry = join(packageDirectory(specifier), "src", "module.ts");
|
||||
if (!existsSync(moduleEntry)) {
|
||||
throw new Error(`${specifier} does not expose src/module.ts`);
|
||||
}
|
||||
// Import the contribution descriptor directly. Package root barrels may
|
||||
// intentionally re-export pages and would otherwise defeat route splitting.
|
||||
return `export { default } from ${JSON.stringify(moduleEntry)};`;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -88,9 +112,8 @@ export default defineConfig({
|
||||
include: ["@xyflow/react"]
|
||||
},
|
||||
build: {
|
||||
// Full-product builds include the host shell plus all installed module wiring.
|
||||
// Dedicated route/vendor splitting belongs in a separate performance pass.
|
||||
chunkSizeWarningLimit: 1200
|
||||
manifest: true,
|
||||
chunkSizeWarningLimit: 500
|
||||
},
|
||||
resolve: {
|
||||
preserveSymlinks: false,
|
||||
@@ -132,6 +155,7 @@ export default defineConfig({
|
||||
fileURLToPath(new URL('../../govoplan-postbox/webui', import.meta.url)),
|
||||
fileURLToPath(new URL('../../govoplan-risk-compliance/webui', import.meta.url)),
|
||||
fileURLToPath(new URL('../../govoplan-scheduling/webui', import.meta.url)),
|
||||
fileURLToPath(new URL('../../govoplan-search/webui', import.meta.url)),
|
||||
fileURLToPath(new URL('../../govoplan-views/webui', import.meta.url)),
|
||||
fileURLToPath(new URL('../../govoplan-workflow/webui', import.meta.url))
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user