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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@wc-toolkit/dce-generator

v1.0.0-alpha.2

Published

[![NPM Version](https://img.shields.io/npm/v/dce-generator.svg)](https://www.npmjs.com/package/dce-generator) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Readme

WC Toolkit - Declarative Custom Element Generator

NPM Version License: MIT

NOTE This is a proof-of-concept and is not intended for production use.

A tool for generating static HTML templates from Web Components, allowing you to use custom elements in a declarative manner without relying on JavaScript for rendering.

Why Use DCE Generator?

Web Components are powerful, but they require JavaScript to initialize and render their shadow DOM. This tool solves several key problems:

  • Server-Side Rendering: Pre-render web components for SSR frameworks
  • Static Site Generation: Use web components in static site generators
  • No JavaScript Fallbacks: Provide HTML-only fallbacks for progressive enhancement
  • Framework Integration: Make it easier to integrate web components with frameworks that expect templates

Installation

# Using npm
npm install dce-generator --save-dev

# Using yarn
yarn add dce-generator --dev

# Using pnpm
pnpm add -D dce-generator

Usage

The DCE Generator works by using Puppeteer to render your web components in a headless browser, extract their shadow DOM content, and save it as static HTML templates.

Basic Example

import { generateDeclarativeCustomElements } from "dce-generator";
import manifest from "./path/to/custom-elements.json";

// Generate templates
await generateDeclarativeCustomElements(manifest, {
  outdir: "./output",
  fileName: "my-components",
  minify: true,
  moduleName: "MyComponents",
});

Configuration Options

type DceGeneratorConfig = {
  /**
   * Path to the output directory
   * @default "./"
   * @example "./output"
   */
  outdir?: string;
  /**
   * Name of the output file
   * @default "declarative-custom-elements"
   * @example "my-custom-elements.html"
   */
  fileName?: string;
  /**
   * Minify the output HTML and CSS
   * @default false
   */
  minify?: boolean;
  /**
   * Module name for the generated file
   * @default "DeclarativeCustomElements"
   */
  moduleName: string;
  /**
   * Path to the module where the custom elements are defined
   * @example (name, tagName) => `./dist/components/${name}/${tagName}.js`
   */
  modulePathTemplate?: (name: string, tagName?: string) => string;
  /**
   * Path to the global module where all components are defined
   * @example "./dist/index.js"
   */
  globalModuleTemplate?: string;
  /**
   * Custom wrapper templates for the generated file
   */
  customWrapperTemplates?: WrapperTemplate[];
  /**
   * Timeout for rendering components in the headless browser
   * @default 1000
   */
  loadTimeout?: number;
  /**
   * JavaScript framework wrapper components
   * @default ['vue', 'jsx', 'svelte', 'angular', 'html', 'esm']
   */
  wrapperComponents?: Array<
    "vue" | "jsx" | "svelte" | "angular" | "html" | "esm"
  >;
};

Custom Module Path

If your components are in individual modules:

await generateDeclarativeCustomElements(manifest, {
  modulePathTemplate: (name, tagName) =>
    `./dist/components/${name}/${tagName}.js`,
});

Global Module

If all your components are in a single bundle:

await generateDeclarativeCustomElements(manifest, {
  globalModuleTemplate: "./dist/all-components.js",
});

Output Format

The generated HTML file contains declarative templates for each web component:

<!-- Generated Component Templates -->

<definition name="my-button">
  <template id="my-button">
    <!-- CSS from shadow DOM or Adopted Stylesheets -->
    <style>
      .button {
        color: blue; /* styles from shadow DOM */
      }
    </style>
    <!-- HTML from shadow DOM -->
    <button class="button">
      <slot></slot>
    </button>
  </template>
</definition>

<!-- More component templates... -->

Performance Optimization

The tool includes several optimizations:

  • Removal of empty CSS properties
  • Minification option to reduce file size
  • Parallel processing of components
  • Cleanup of comments and whitespace