Repository navigation
Replies: 1 comment
|
You can render a stylesheet For example, in <script setup>
import sharedCssUrl from './assets/pm-common.css?url'
</script>
<template>
<link rel="stylesheet" :href="sharedCssUrl">
<div class="your-component">...</div>
</template>Register it with I tested a two-element example with Vite 6.0.3, Vue 3.5.13, and plugin-vue 5.2.1: in dev both shadow roots linked For your library/module build, deployment needs attention: my ES-library build emitted The shared URL permits normal browser caching, rather than guaranteeing one network request under all cache settings. External links can briefly show unstyled content, and I did not test CSS HMR for the References: Vite URL imports, Vue custom-element styles. AI-assisted, with the development and production browser checks described above run locally. |
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
I am using Vite in module mode to build a Vue 3 project that defines 4 web components with shadow root enabled. The components share lots of common CSS, which currently is inlined as <style> tags into each shadow root, and thus is loaded once for each component on a page.
I'd like to try using tags in the shadow DOM hoping the browser will download the CSS only once, however I can't figure out how to configure Vite to achieve this?
I have searched existing issues & discussions but I can't find a clear explanation of how to control how Vite treats imported styles. Ideally I'd like this to work in dev mode.
Currently the project looks like this:
main.ts
dayEvents.ts:
PMDayEvents.vue
Any help with this would be greatly appreciated... thanks!
Franck
All reactions