Open SumNeuron opened 4 years ago
I have tried a bunch of stuff
// rollup.entry.js
let components = {
CountButton
}
// BEGIN: @vue/web-component-wrapper
// helpers for registering with window
const pascalToKebabHelper = (x, y) => `-${y.toLowerCase()}`
const pascalToKebab = (str) => {
return str.replace(/\.?([A-Z]+)/g, pascalToKebabHelper).replace(/^-/, "")
}
let GlobalVue = null;
let GlobalVuetify = null;
// define webcomponents
if (typeof window !== 'undefined') {
// vue / vuetify from cdn
GlobalVue = window.Vue;
GlobalVuetify = window.Vuetify
let vuePlugins = GlobalVue._installedPlugins
let vuetifyFound = false
for (let i = 0; i < vuePlugins.length; i++) {
let plug = vuePlugins[i]
if (plug.name === 'Vuetify') {
vuetifyFound = true // Vue.$_vuetify_installed = true, but Vue._installedPlugins[0].installed = false
// tried manually installing vuetify, didn't work
// if (plug.installed === false) {
// plug.install()
// plug.installed = true
// }
break
}
}
if (!vuetifyFound) {
// GlobalVue.use(plugin);
GlobalVue.use(GlobalVuetify)
}
console.log(GlobalVue)
Object.keys(components).forEach(name=>{
let htmlTagName = pascalToKebab(name) // <--- too lazy to wrangle pascal to kebab case
// let vueWebComponent = wrap(new Vue({}), components[name]) // tried new Vue but complains about constructor
let vueWebComponent = wrap(GlobalVue, components[name]) // this doesn't work with vuetify
window.customElements.define(htmlTagName, vueWebComponent)
})
}
// END: @vue/web-component-wrapper
Loading the .css in the component. It worked for me.
<template>
<div>
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet" />
.
.
.
<div>
<template>
@SumNeuron have you ever found a solution for this?
Cool stuff you're doing here.
How I got here:
mkdir test && cd test
vue-cli
:vue create dev
cd dev && vue add veutify
test/dev
up totest
vue.config.js
to point to new location:CountButton.vue
which is just a wrapper of the Vuetify component<v-btn>
imported a la carte (seetest/dev/components/CountButton.vue
)CountButton
indev/src/main.js
e.g.CountButton.vue
was mounted and data was reactive in Vue inspector, but not the template)dev/src/App.vue
to contain justCountButton.vue
dev/src/App.vue
todev/src/App0.vue
and tried mounting theApp0
component. This failed in the same manner as (8) as thevue-cli
targetsdev/src/App.vue
as the entry point.package.json
inspected the resulting
dist/pub.min.js
anddist/demo.html
files and noticed the component regained its dynamic template - error from (8) - but lost all stylingThought that this may be due to Vuetify styles not being bundled with the the Vuetify component
Setup rollup to try and force the CSS to be bundled with the component (see
rollup.config.js
,dev/src/rollup.entry.js
andpackage.json
)then I rolled up
npm run build:r
then I tried to use the component: (
dist/demo.html
)Am back to where I was at step (13); namely, I have WebComponents, but despite bundling
vuetify.min.css
with theCountButton.vue
component, but no styling.This belabored process raises two questions:
The former is related more to
vue-cli
(but if you know the answer I'd appreciate it) The latter is where my issue comes from.How can I have
@vue/web-component-wrapper
convert my component and either include the requisite styles or use the stylesheets from a cdn?a MWE repo to help figure this out can be found here