vite-plugin-vue-shadow-style
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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>

Package Sidebar

Install

npm i vite-plugin-vue-shadow-style

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

15.3 kB

Total Files

9

Last publish

Collaborators

  • kainstar