npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@timeraa/vue3-web-component

v1.0.0

Published

Create full vue3 apps inside embeddable components.

Downloads

6

Readme

vue3-web-component

Create full vue3 apps inside embeddable components.

Why?

Vue3 supports web components out of the box, but it's not easy to create a full app inside a web component. This project aims to make it easy to create full vue3 apps inside embeddable components. There were also a lot of issues I encountered when trying to create a web component with vue3 only like styles not being applied, plugins not easily being able to be used as you don't have an app instance like usual by default and most importantly if you want to use this as an embeddable script on let's say a customers homepage and they want to override some styles, you can't do that with vue3 out of the box due to its shadow dom usage. This project aims to solve all of these issues.

How?

This module exposes 2 functions, one is the plugin which only takes care of styles being applied and copied over from the host page and the other one is a function that basically works like createApp from vue (even uses it under the hood) but allows you to easily use the app instance to register the plugins you love.

What happens in the background is pretty straightforward, we walk through all the styles that you have in components (nested ones as well) and collect them using a mixin. Then we create a new style tag inside of the shadow dom and copy over all the styles we collected. and onUnmounted we remove the style tag again preventing styles from overriding something that isn't rendered, this also allows for HMR to work as expected as each style tag has the component's uid assigned to them.

After this is done we copy over the host's styles to the shadow dom (at the bottom of the component's styles), this allows for the host page to override styles if needed for let's say themes.

Known issues

  • Currently HMR does not work for copying over the host's styles as there is no monitoring and managing of wether those styles changed (When the project is built and the host page's styles change)

TODO

  • [ ] Add tests
  • [ ] Add support for HMR for host styles

Usage

main.js/main.ts

import "./index.css";

import App from "./App.vue";
import { createWrappedWebComponent } from "vue3-web-component";

customElements.define(
	"your-custom-element",
	createWrappedWebComponent(App, app => {
		//* Use app like normal
		// app.use(createI18n())
		// app.use(createPinia())
	})
);