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

vue-webcomponents-plugin

v1.0.1

Published

A Vue.js plugin that allows you to use and create webcomponents as easily as Vue Components

Downloads

2

Readme

Vue Webcomponents Plugin

This plugin allows you to work with native webcomponents in Vue.js as if they were Vue Components. It adds a Vue.webComponent() function that behaves similarly to Vue.component(), and allows you to add a ..., webComponents:{}, ... attribute to a Component definition that behaves similarly to ..., components:{}, ....

Note that this does nothing to try to abstract the WebComponents API to a 'vue-like' experience. Working with this plugin requires creating web component definitions that are compatible with customElements.define as explained below.

See https://developers.google.com/web/fundamentals/web-components/customelements for a guide on creating your own WebComponents.

This plugin does no kind of transpilation or polyfilling, that's up to you to provide in whichever way you feel is best. If you provide the plugin valid definitions, it will work. Babel by default will break class extends HTMLElement. The fastest way around this is to add the directory with your web component definitions to babel's ignored list, though that probably won't work for something in production.

Installation

npm i vue-webcomponents-plugin -S

Usage

import Vue from 'vue';
import WebcomponentsPlugin from 'vue-webcomponents-plugin';
import WebComponentDefinition from 'some/path/to/a/valid/definition';
import MyCoolComponent from 'some/path/to/a/valid/definition';

Vue.use(WebcomponentsPlugin);

Vue.webComponent('name-of-component', webComponentDefinition);
//or
new Vue({
    template:`<div><web-component-definition @customEvent="" :some-attribute=""></web-component-definition></div>`,
    webComponents: {
        WebComponentDefinition,
        MyCoolComponent
    }
})

Using either Vue.webComponent or ..., webComponents:{}, ... will register the web component with customElement.define and add the web component name to Vue's Vue.config.ignoredElements array so Vue doesn't warn against unregistered elements in component templates. Note: webcomponent definitions should only be declared once and are not scoped, so, no matter where they are declared they will be available anywhere in the application.

Name

Name as passed to Vue.webComponent(name, definition) or {webComponents:{MyName:definition}}can be kebab-case, PascalCase, or camelCase, e.g., 'my-cool-component', 'MyCoolComponent', or 'myCoolComponent'

Webcomponent Definition

A Webcomponent Definition can be a string, class, object or a function

String Definition

WebComponentDefinition: `<template></template><script></script>`

  • where creates the class that extends HTMLElement, invokes customElements.define and clones/gets content from the template. <template> is required for this definition and must be written the script. If you want to pass just a class, use the Class Definition.
Class Definition

WebComponentDefinition: class extends HTMLElement{}

  • pass a class that extends HTMLElement.
Object Definition
  WebComponentDefinition: {
    //template should include one root template element to be consumed by class
    template:'<template></template>',
    // elementClass used to extend HTMLElement, can consume the template element via DOM selectors
    elementClass: class extends HTMLElement{},
    //definition is as defined above. Cannot be used with template or class
    definition: `<template></template><script></script>`,
    // async defaults to false, if true, instantiates the customElement in a requestIdleCallback
    async: Boolean 
  }
Function Definition:

WebComponentDefinition: () => import('path/to/definition')

  • function that returns any of the above or a promise that resolves any of the above in a Promise.