Build Pipeline
When you run npx cook build, Cook executes a deterministic sequence of plugins that transform your src/ directory into a production-ready dist/ directory. Understanding the order helps when writing custom plugins or debugging output.
Pre-file plugins
These run once before any individual file is processed:
- Create dist -- creates the
dist/directory if it does not exist - Copy src -- copies everything from
src/intodist/ - Process markdown -- converts
.mdfiles to HTML, parses YAML frontmatter, and builds collections - Optimize images (generate) -- produces AVIF/WebP derivatives at multiple widths (320, 640, 960, 1280, 1920)
- Custom plugins: before -- runs any plugins registered in
plugins.before - Create directories from files -- converts
about.htmltoabout/index.htmlfor clean URLs
Per-file loop
Every allowed HTML file in dist/ is processed through these steps in order:
- Frontmatter -- extracts and removes YAML frontmatter from HTML files
- Escape code blocks -- base64-encodes
<code-block>content so JSDOM-based plugins cannot alter it - Custom plugins: default -- runs any plugins registered in
plugins.default - Apply template -- wraps the file in its layout template (
data-templateattribute or frontmatterlayout) - Includes -- resolves
data-includeelements by inlining external HTML partials - Repeat -- expands
data-repeatelements for each item in a collection - Components -- replaces custom elements and
data-componentelements with their templates - Template strings -- resolves
${variable}expressions using global data merged with frontmatter - Image rewrite -- rewrites
<img>tags to<picture>elements with responsivesrcset - Auto-components -- detects custom elements and manages Vanilla Breeze JS loading
- Declarative Shadow DOM -- pre-renders shadow DOM content for web components
- External links -- adds missing
http://protocol to external link hrefs - Inline -- replaces
data-inlinelinks and scripts with their file contents - Active links -- marks
<a>elements whosehrefmatches the current page - Bundle -- collects CSS and JS marked for bundling
- Minify -- minifies the HTML source
- Restore escaped content -- decodes base64 code-block content back to its original form
The modified source is then written back to the file.
Post-file plugins
After all files are processed:
- Fragments -- generates
_fragment.htmlfiles containing only the<main>content for SPA navigation - Formats -- generates markdown, JSON, Atom feed, and llms.txt variants
- Sitemap -- when
sitemap.urlis set, createssitemap.xmlfrom all pages in the site root (dist/, ordist/<siteRoot>/) - Bundle build -- writes the collected CSS/JS bundles to
dist/ - Custom plugins: after -- runs any plugins registered in
plugins.after
Custom plugins
Custom plugins are ES6 classes with an init() method. Cook imports the class, instantiates it with {file, data}, and calls init(). The init method can be async.
export class AddBuildDate { constructor({file, data}) { this.file = file; this.data = data; }<p></p><p> async init() { // Add a build timestamp to every page const timestamp = new Date().toISOString(); this.file.src = this.file.src.replace( '</body>', <code><!-- Built: ${timestamp} --></body></code> ); }}</p>
Registering plugins
Register plugins in config/main.js under the plugins key. Each array takes plugin filenames (without .js) relative to your pluginPath directory (default: plugins/).
export default { plugins: { before: [], default: ['add-build-date'], after: ['generate-search-index'], }, pluginPath: 'plugins',};
before-- runs once before the file loop (receives no individualfileobject)default-- runs once per file during the file loop (receives the currentfileobject)after-- runs once after the file loop and all post-processing
Plugins within each array execute in order from left to right. If one plugin depends on another, list the dependency first.