Starter for creating agnostic WebComponents using Vue and UnoCSS
Starter for creating agnostic WebComponents using Vue and UnoCSS
Sometimes when you want to build some embed UI for websites/apps you might not have control with.
For example, injected UI in web browser extensions, or dev tool UI etc. In those cases, styling can be a headache, because the CSS selectors are applying to the whole page and inferrance might occur.
We have nice tools like Vue’s Scoped CSS, or native Nested CSS, but they only prevent the styles from leaking out, but can’t prevent users styles from sneaking in. Some workarounds like rasing the specificity by using more selectors, or applying !important to every rules. However, those workarounds make it a lot harder to work with but still no guarantee to always work.
Shadow DOM is the only solution for the true style isolation, while the bare API is not very friendly work with.
We as developers, surely we want to use the stack that works the best to us. In my case, it’s Vue for logic and UnoCSS for style. Unlike plain JavaScript you can directly bundle into a library, using Vue SFC and UnoCSS to build an agnostic library can be a bit tricky to set up.
That’s why I created this starter, to help you quickly build an agnostic library using the tools with the best developer experience.
scripts/build-css.ts to generate the CSS tokens with UnoCSS.unplugin-vue to bundle the Vue components into JavaScript.tsdown to build the library (can be any build tool that supported by unplugin).defineCustomElement to define the WebComponents.MIT License © Anthony Fu
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.