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

custom-element-vuejs-integration

v1.3.3

Published

Types for integrating custom elements into Vue.js projects

Downloads

1,267

Readme

Custom Elements Vue.js Integration

This package is designed to generate types for your custom elements in a project using Vue.js. These types will generate inline documentation, autocomplete, and type-safe validation for your custom elements in a Vue.js application.

NOTE: This will generate types for both vue templates and JSX.

Usage

This package includes two ways to generate the custom data config file:

  1. calling a function in your build pipeline
  2. as a plugin for the Custom Element Manifest Analyzer

Install

npm i -D custom-element-vuejs-integration

Build Pipeline

import { generateVuejsTypes } from "custom-element-vuejs-integration";
import manifest from "./path/to/custom-elements.json" assert { type: "json" };

const options = {
  outdir: "./",
  fileName: "my-library-vuejs.d.ts",
  globalTypePath: "./dist/components/index.js", // relative to `outdir`
};

generateVuejsTypes(manifest, options);

Update tsconfig.json with Local Reference

Now you can add a reference to the types in your tsconfig.json.

{
  "compilerOptions": {
    "types": ["./my-library-vuejs"]
  }
}

CEM Analyzer

Set-up

Ensure the following steps have been taken in your component library prior to using this plugin:

Import

// custom-elements-manifest.config.js

import { customElementVuejsPlugin } from "custom-element-vuejs-integration";

const options = {
  outdir: "./dist",
  fileName: "my-library-vuejs.d.ts",
  globalTypePath: "./components/index.js", // relative to `outdir`
};

export default {
  plugins: [customElementVuejsPlugin(options)],
};

Update tsconfig.json with Package Reference

Now you can add a reference to the types in your tsconfig.json.

{
  "compilerOptions": {
    "types": ["my-library/my-library-vuejs"]
  }
}

Configuring Your Vue.js Project

If you haven't configured your Vue.js project to work with custom element/web components, follow the instructions here based on your project type to ensure the components work correctly.

Configuration

The configuration has the following optional parameters:

{
  /** Path to output directory */
  outdir?: string;
  /** File name for the types */
  fileName?: string | null;
  /** Class names of any components you would like to exclude from the types */
  exclude?: string[];
  /** Indicates if the component classes are a default export rather than a named export */
  defaultExport?: boolean;
  /** Used to get type reference for components from a single source */
  globalTypePath?: string;
  /** Used to get types from specific path for a given component */
  componentTypePath?: (name: string, tag?: string) => string;
  /** The property form your CEM component object to display your types */
  typesSrc?: string;
  /** Used to add global element props to all component types */
  globalEvents?: string;
  /** Hides logs produced by the plugin */
  hideLogs?: boolean;
  /** Prevents plugin from executing */
  skip?: boolean;
  /** Adds a prefix to tag name references */
  prefix?: string;
  /** Adds a suffix to tag name references */
  suffix?: string;
}

Configuration

Output

You can configure the destination and the file name of the generated type file using the outdir and fileName configuration.

{
  /** Path to output directory */
  outdir: 'dist',
  /** File name for the types */
  fileName: 'vuejs-integration.d.ts'
}

Default Exports

If you component class does not provide a named export and is the default export, be sure to set defaultExport to true. This will endure the import for the class gets resolved correctly.

Types

If your components were built using TypeScript, the types should automatically be used when you reference the corresponding module.

NOTE: All type paths should be relative to the location specified in the outdir option.

If your types are rolled up into a single type declaration file, you can set the globalTypePath option to the location of that file.

{
  globalTypePath: ".dist/components/index.js";
}

If each of the component type definitions are split out by each component, you can use the componentTypePath to reference individual component paths.

{
  componentTypePath: (name, tag) => `./components/${tag}/${name}.js`;
}

Custom Types

If you have custom types configured in your Custom Elements Manifest and do not have types or are unable to use them, you can specify the property name of that type using the typeSrc option.