I am struggling with getting a packaged component to display its dynamically loaded components. When I run the bundle standalone everything works nice. When used as external library the props arrive at the lib, but the dynamic components are not rendered.
package.json - package
{
"name": "pfg-formwizard",
"version": "0.0.0",
"main": "./dist/pfg-formWizard.umd.js",
"module": "./dist/pfg-formWizard.es.js",
"exports": {
".": {
"import": "./dist/pfg-formWizard.es.js",
"require": "./dist/pfg-formWizard.umd.js"
},
"./dist/style.css": "./dist/style.css"
},
"files": [
"dist"
],
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"uuid": "^8.3.2",
"vue": "^3.2.25"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.0.0",
"autoprefixer": "^10.4.2",
"postcss": "^8.4.6",
"tailwindcss": "^3.0.18",
"vite": "^2.7.2"
}
}
vite.config.js - package
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const path = require('path');
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, "src/components/index.js"),
name: "pfg-formWizard",
fileName: (format) => `pfg-formWizard.${format}.js`
},
rollupOptions: {
external: ["vue"],
output: {
globals: {
vue: "Vue",
}
}
}
},
plugins: [vue()]
})
published component - package
<template>
<div class="bg-amber-200 pfg-formWizard h-full">
<h1 class="max-w-5xl mx-auto text-xl">{{form.name}}</h1>
<form @submit.prevent="onSubmit" class="w-full">
<div class="max-w-5xl container mx-auto">
<p>{{form.schema}}</p>
<p
v-for="element in form.schema"
>{{element}}</p>
<component
v-for="element in form.schema"
:is="components[element.component]"
:section="element"
></component>
</div>
<FormControls class="max-w-5xl container mx-auto" />
</form>
</div>
</template>
<script>
export default {
name: 'FormWizard',
}
</script>
<script setup>
import FormSection from "./wizard/FormSection.vue";
import FormControls from "./wizard/FormControls.vue";
const components = {
FormSection,
}
const props = defineProps({
form: {
type: Object,
required: true
},
})
[...]
</script>
Note that when using this package this FormWizard component renders correctly, the {{form.name}} displays and renders too.
The dynamic <component :is=”[…]” does somehow not work, although the props are there.
The
{{form.schema}}
displays the json object array string correctly.
The does not display at all.
/src/components/index.js - package
import FormWizard from "./FormWizard.vue"
export {
FormWizard,
}
All my research led to dead ends. What am I missing?
Any hint greatly appreciated!