vite-plugin-vue-shadow-style

Plugin to inject Vue setup SFC style to shadow root
1,472 1
Install
npm install vite-plugin-vue-shadow-style
Latest Version:1.0.0
Vue:3
License:MIT
Last Updated:Jan 5, 2024
Links: GitHub  ·  npm
Maintainer: kainstar

vite-plugin-vue-shadow-style

npm package Build Status Downloads Issues Code Coverage Commitizen Friendly Semantic Release

Plugin to inject Vue setup SFC style to shadow root.

Typically, the framework injects the style into the document head when assets are loaded, indicating that it is static. However, in the shadow DOM, the style should be injected dynamically into the shadow root where the component is rendered.

This plugin will recognize the style blocks with the shadow attribute and help you inject them into the shadow root in runtime.

Install

npm install vite-plugin-vue-shadow-style --save-dev
yarn add vite-plugin-vue-shadow-style -D
pnpm add vite-plugin-vue-shadow-style -D

Usage

Config Bundler

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

import vueShadowStyle from 'vite-plugin-vue-shadow-style';

export default defineConfig({
  plugins: [vue(), vueShadowStyle()],
});

Write SFC

This plugin use composition API to inject style to shadow root, so you should use <script setup> to write your component.

<script setup lang="ts"></script>

<template>
  <h1>Vue in Shadow DOM</h1>
</template>

<!-- Add `shadow` attr on style block which you want to inject in runtime -->
<style scoped shadow>
h1 {
  color: red;
}
</style>

<!-- import other files also okay -->
<style src="./style.scss" shadow></style>

Related Packages

unplugin-vue-markdown

Compile Markdown to Vue component

4,031,626 626
unplugin-vue-prop

Add import define props type support for Vue3 script-setup and lang is typescrip...

1,105 2
unplugin-vue-i18n

这是一个使用unplugin创建的vite插件, 服务于vue3, 进行i18n国际化转换

8,203
unplugin-image

A universal bundler plugin which imports JPG, PNG, GIF, SVG, and WebP files.

40,041 1
unplugin-config

Register global imports on demand for Vite and Webpack

33,928 28

Version History

Version Released Vue License
1.0.0 ^3.0.0 MIT