<link rel="stylesheet" href="/_merged_assets/_static/search/noscript.css">
Custom Elements Manifest Custom Elements Manifest Analyzer Blog Playground Toggle darkmode

Plugins: Introduction

You can also write custom plugins to extend the functionality to fit what your project needs. You can extract custom JSDoc tags for example, or implement support for a new Web Component library.

TIP: You can use the online playground for quickly prototyping plugin ideas, right in the browser

A plugin is a function that returns an object. You can read about plugins in more detail in the authoring plugins documentation. There are several hooks you can opt in to:

  • initialize: Can be used to run setup code in your plugin, runs before analysis
  • collectPhase: First passthrough through the AST of all modules in a project, before continuing to the analyzePhase. Runs for each module, and gives access to a Context object that you can use for sharing data between phases, and gives access to the AST nodes of your source code. This is useful for collecting information you may need access to in a later phase.
  • analyzePhase: Runs for each module, and gives access to the current Module's moduleDoc, and gives access to the AST nodes of your source code. This is generally used for AST stuff.
  • moduleLinkPhase: Runs after a module is done analyzing, all information about your module should now be available. You can use this hook to stitch pieces of information together.
  • packageLinkPhase: Runs after all modules are done analyzing, and after post-processing. All information should now be available and linked together.

TIP: When writing custom plugins, ASTExplorer is your friend 🙂

To get started developing custom plugins, take a look at the cem-plugin-template repository to quickly get you up and running. Also take a look at the authoring plugins documentation.

custom-elements-manifest.config.mjs:

export default {
  plugins: [
    {
      // Make sure to always give your plugins a name, this helps when debugging
      name: 'my-plugin',
      // Runs before analysis starts
      initialize({ts, customElementsManifest, context}) {},
      // Runs for all modules in a project, before continuing to the `analyzePhase`
      collectPhase({ts, node, context}){},
      // Runs for each module
      analyzePhase({ts, node, moduleDoc, context}){},
      // Runs for each module, after analyzing, all information about your module should now be available
      moduleLinkPhase({moduleDoc, context}){},
      // Runs after modules have been parsed and after post-processing
      packageLinkPhase({customElementsManifest, context}){},
    }
  ]
}

TIP: Make sure to check out the cem-plugin-template repository if you're interested in authoring custom plugins, and check the authoring plugins documentation for more information.

Community Plugins

NameDescription
analyzer-import-alias-pluginplugin to improve handling for import aliased classnames
cem-plugin-async-functionplugin to add (non-standard) async flag to functions
cem-plugin-copyplugin to copy files when finished analyzing
cem-plugin-custom-jsdoc-tagsA tool for mapping custom JSDoc tags to properties in the Custom Elements Manifest.
cem-plugin-expanded-typesa plugin for the CEM Analyzer to parse TypeScript types and provide usable information for tools.
cem-plugin-jsdoc-exampleplugin to handle jsdoc @example tag
cem-plugin-jsdoc-functionplugin to handle jsdoc @function tag on variables
cem-plugin-module-file-extensionsplugin to rewrite file extensions (e.g. from .js to .ts)
cem-plugin-reactifyplugin to automatically create React wrappers for your custom elements
cem-plugin-readonlyplugin to handle read-only class members
cem-plugin-type-descriptions-markdownplugin to add markdown type documentation to manifest member descriptions
custom-element-jet-brains-integrationa mapper to take the information captured in the CEM and generate the appropriate web-types.json file for JetBrains IDEs
custom-element-jsx-integrationa custom type generator to convert the CEM data into usable types to integrate custom elements into non-React projects that use JSX templates
custom-element-lazy-loaderCreate a single entry point to lazy-load your custom elements/web components as needed!
custom-element-react-wrappersa tool for generating react-compatible wrappers for custom elements
custom-element-solidjs-integrationa custom type generator to convert the CEM data into usable types to integrate custom elements into SolidJS projects
custom-element-svelte-integrationa custom type generator to convert the CEM data into usable types to integrate custom elements into Svelte projects
custom-element-vs-code-integrationa mapper to take the information captured in the CEM and generate the appropriate HTML and CSS data files for for VS Code integration
custom-element-vuejs-integrationa custom type generator to convert the CEM data into usable types to integrate custom elements into Vue.js projects
custom-elements-lsptsserver plugin which uses the analyzer and provides intellisense for custom elements in tagged template literals
custom-elements-manifest-inheritanceA tool for mapping inherited content (including class members, attributes, CSS parts, CSS variables, slots, and events) from parent classes in the Custom Elements Manifest.
vite-plugin-cema vite.js plugin based on the @custom-elements-manifest/analyzer

Want your plugin listed here? Please create a PR!