From 68d266711a82b1b702adfb37d472f76c64013f04 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Fri, 13 Sep 2024 10:39:00 +0200 Subject: [PATCH] Bug 37911: (follow-up) Experimental introduction of dynamic imports for code splitting --- .../prog/js/vue/modules/islands.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/islands.ts b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/islands.ts index db8dcb5d92..862a19df4b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/islands.ts +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/islands.ts @@ -1,17 +1,25 @@ import { Component, defineCustomElement } from "vue"; -import HelloIslands from "../components/HelloIslands.vue"; /** * A registry for Vue components. - * @type {Map} + * @type {Map Promise>} */ export const componentRegistry: Map Promise> = new Map( - [["hello-islands", HelloIslands]] + [ + [ + "hello-islands", + async () => { + const module = await import("../components/HelloIslands.vue"); + return module.default; + }, + ], + ] ); // Register and define custom elements -window.requestIdleCallback(() => { - componentRegistry.forEach((component, name) => { +window.requestIdleCallback(async () => { + componentRegistry.forEach(async (importFn, name) => { + const component = await importFn(); customElements.define( name, defineCustomElement(component as any, { shadowRoot: false }) -- 2.46.0