Skip to content

Webpack and Vite plugin to use the adopted stylesheet api with your vue app

Notifications You must be signed in to change notification settings

lseguin1337/vue-adopted-stylesheets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

vue-adopted-stylesheets

Vite plugin to use the adopted stylesheets api with your vue app

Install

yarn add -D vue-adopted-stylesheets @vitejs/plugin-vue

Plugin Usage

// vite.config.js
const { defineConfig } = require('vite');
const vue = require('@vitejs/plugin-vue');
const { vueAdoptedStylesheetsPlugin } = require('vue-adopted-stylesheets');

module.exports = defineConfig({
  // ...
  plugins: [
    vue({
      // any vue config plugin...
      customElement: true, // this is mandatory to make working the plugin
    }),
    vueAdoptedStylesheetsPlugin(),
  ]
});

Unlocked use cases

Simply exemple to use your app inside a webcomponent wrapper

import { createApp } from 'vue';
import App from './App.vue';

class MyApp extends HTMLElement {
  constructor() {
    super();
    const app = createApp(App);
    app.mount(this.attachShadow({ mode: 'open' }));
  }
}

customElements.define('my-app', MyApp);

Bootstrap your vue app inside any shadow root you want

// main.js
import { createApp } from 'vue';
import App from './App.vue';

const app = createApp(App);

// Now you can mount your vue app inside a shadow root all the styling would be properly injected
app.mount(document.querySelector('#custom-element-with-shadow-root').shadowRoot);

Note

This plugin is working even if the vue library is externalized

About

Webpack and Vite plugin to use the adopted stylesheet api with your vue app

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published