Appearance
Demo
https://stackblitz.com/~/github.com/EranGrin/element-plus-unocss-web-component
Usage
UnoCSS + Vite
Install UnoCSS plugin for Vite based on unocss vite plugin
Add shadow dom option to the vite plugin:
javascriptUnoCSS( { mode: 'shadow-dom', }),
you can add any global css to this file
Add create style.css file:
css@unocss-placeholder;
you can add any global css to this file
Import the style.css file with ?inline:
javascriptimport style from './style.css?inline';
Create your web component passing the style variable as the cssFrameworkStyles option:
javascriptcreateWebComponent({ rootComponent: App, elementName: 'my-web-component', plugins: pluginsWrapper, cssFrameworkStyles: style, VueDefineCustomElement, h, createApp, getCurrentInstance, disableStyleRemoval: false, });
In Components: All Components that use UnoCSS should have the @unocss-placeholder directive at the top of the style tag
css<style> @unocss-placeholder; .any-other-css { color: red; } </style>
Fonts workaround:
?inline can not handle import url() in css therefore fonts are not loaded, workaround is to add font css to the App.vue