Auto-Components

The auto-components plugin scans each built HTML page for custom element tags (any tag containing a hyphen), determines which need JavaScript, and optimizes loading accordingly. Pages that only use CSS-only elements get zero JavaScript. Pages that need JS get fine-grained import maps instead of a monolithic bundle.

How it works

  1. Cook scans the page for all custom element tags (e.g. <site-header>, <tab-set>)
  2. Each tag is checked against the cssOnly list
  3. If no tags require JS, the Vanilla Breeze bundle script is removed entirely
  4. If JS-requiring tags exist and a manifest is provided, Cook generates an import map for only the needed components and removes the bundle
  5. If JS-requiring tags exist but no manifest is available, the full bundle is kept

CSS-only elements

Some custom elements are implemented with CSS alone and never need JavaScript. List them in the cssOnly config to strip the JS bundle from pages that only use those elements:

A page using only <layout-stack> and <icon-symbol> will have the Vanilla Breeze script tag removed from the output, resulting in a zero-JS page.

Import map generation

When a component manifest is provided, Cook generates a per-page import map so only the components actually used on that page are loaded:

The manifest is a JSON file mapping tag names to JS file paths:

For a page that uses <tab-set> and <layout-stack>, Cook injects an import map and module script for tab-set only, and removes the bundle script tag.

Cook DSD component scripts

When Cook-authored DSD components (see Declarative Shadow DOM) have companion .js hydration files, the auto-components plugin detects them and injects individual <script type="module"> tags rather than relying on the VB bundle.

Configuration reference

OptionDefaultDescription
enabledfalseEnable the auto-components plugin
cssOnly[]Array of tag names that use CSS only
manifestnullPath to component manifest JSON (relative to dist)
bundlePattern/vanilla-breeze[^"']*\.js/Regex to match VB bundle script tags for removal

For third-party web-component packages from npm, see Package Components.