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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-grundlage

v0.1.0

Published

Vite plugin that prerenders grundlage web components to declarative shadow DOM at build time.

Readme

vite-plugin-grundlage

A Vite plugin that renders grundlage components on the server and inlines the result into the HTML as declarative shadow DOM. Markup and styles are there when the HTML is first parsed, and on the client grundlage hydrates that markup instead of rendering it again.

Own package, own version, and a lot younger than the library, so the API can still move between minor versions. Nothing here is needed to use grundlage itself.

introduction

getting started

installation

npm install --save-dev vite-plugin-grundlage
  • Vite 8 as a peer dependency
  • Node 24 or newer, the file scan uses glob patterns that older versions don't take
  • happy-dom comes along as a dependency, it is the DOM the components render into on the server

example

// vite.config.ts
import { defineConfig } from "vite";
import { prerenderWebcomponents } from "vite-plugin-grundlage";

export default defineConfig({
	plugins: [prerenderWebcomponents()],
});
<click-counter start="3" ssr></click-counter>
<!-- prerendered into the page -->
<click-counter start="3"></click-counter>
<!-- left alone, rendered on the client -->

concepts

opt in per element

Only the elements carrying the sentinel attribute (ssr by default) prerender, in dev and in build. The attribute stays on the output, so client code can branch on host.hasAttribute("ssr").

components are found, not registered

There is no tag-to-module map to maintain. Every source file under the Vite root is imported and the tags those modules registered are read back from customElements, which means module side effects do run at build time. node_modules, dist, build, declaration files, test/spec/bench files and *.config.* are always skipped.

include and exclude narrow that down, both relative to the Vite root. include replaces the default "everything" pattern, exclude is added to the built-in skip list:

prerenderWebcomponents({
	include: ["src/components/**/*.ts"],
	exclude: ["**/*.stories.ts"],
});

the module loader

Component modules are loaded through Vite's own SSR pipeline, so TypeScript, extensionless and directory imports, aliases and the project's own plugin transforms all work the way they do in the app. To get that, the plugin boots a throwaway Vite server that re-runs the project's vite.config. Two things follow from that:

  • the config is evaluated a second time per build, so a plugin with heavy or one-shot side effects in config or buildStart sees them run twice
  • the loader is a serve-mode server, so plugins declaring apply: "build", or branching on config.command, take their dev path for component modules

componentLoader: "isolated" skips all of it and boots a bare loader that only inherits the resolve settings. Faster, but project plugins don't transform component modules. It is also the automatic fallback when there is no config file on disk. Either way, a module that throws while loading is reported and skipped rather than failing the build.

light-DOM children

Children are kept as they were written, next to the inlined shadow root, so the browser projects them into their <slot>s while parsing and slotted content is styled at first paint too.

<user-card ssr>
	<h2 slot="name">Ada</h2>
</user-card>
  • children are attached to the host before the component mounts, so a component reading its own light DOM (host.children, slot.assignedNodes()) sees the real thing during prerender
  • a registered component sitting in that light DOM is rendered along with its parent, sentinel or not

options

| option | default | effect | | --------------------- | ------------------ | ------------------------------------------------------------------------------------ | | include | every source file | globs (relative to the Vite root) of the modules to import for component definitions | | exclude | — | globs added to the built-in skip list | | componentLoader | "project-config" | "isolated" loads component modules without re-running the project's vite.config | | sentinelAttribute | "ssr" | the marker attribute that opts an element in | | firstYieldTimeoutMs | 5000 | how long to wait for the first paint before giving up and leaving it for the client |

fallbacks

The plugin degrades to client render whenever it can't serialize an element. Each case logs a [prerender] warning and ships a working page:

  • a { mode: "closed" } shadow root, happy-dom can't serialize it
  • no shadow content within firstYieldTimeoutMs
  • a tag no scanned module defines, widen include if the module lives elsewhere
  • any throw during prerender