I got a vueJS app where people can use widgets. Widgets are composed of 2 VueJS components and an index.ts where the index.ts export default object like :
{name: "Foo", component: vueComponent, settingsComponent; OtherVueComponent}.
This is bundled with vite:
build({
plugins: [vue()],
build: {
lib: {
entry: [path.resolve(dataComponentsDir, dataComponent, "index.ts")],
name: dataComponent,
fileName: (_format) => `${dataComponent}.js`,
formats: ["es"],
},
rollupOptions: {
external: ["vue", "typeorm", /^@repo\//, "vue-echarts", /^echarts\//],
output: {
inlineDynamicImports: false,
preserveModules: false,
format: "es",
exports: "named",
globals: {
vue: "Vue",
},
},
},
preserveEntrySignatures: "strict",
outDir: path.resolve(tempDir, dataComponent),
emptyOutDir: true,
},
});
. It gives me a one JS file esmodule that i stored as base64 in a postgreDB. My issue is how could i now import and use this module in a vue client?
I tried to import the modules but they cannot access vue, echarts and other external libraries: TypeError: Failed to resolve module specifier "vue".
Here is how i import modules:
const moduleText = atob(base64Module);
const blob = new Blob([moduleText], { type: 'application/javascript' });
const moduleURL = URL.createObjectURL(blob);
try {
const module = await import(moduleURL);
} catch(e) {
console.error(e)
}
I was expecting import to share current context.
vueimport to window.Vue global. A more high-tech way is to use module federation for chunks that are supposed to be loaded separatelyimportkeyword inside so i can't figure out how i can make it through global scope.vue: 'Vue'instead ofreact: 'react'