d8e
v1.11.1
Published
CLI tool for bundling vanilla/plain HTML, CSS & JS.
Readme
d8e
A CLI tool for bundling/preparing vanilla HTML, CSS & JS for deployment.
Setup
1. npm install -g d8e@latest
2. Structure your codebase like this:
src/
-> index.html
-> style
-> main.css
-> script
-> main.js
-> asset
-> video
-> img
-> font3. Run d8e
d8e --help prints the usage. The other flags are --pjax, --clean-urls, --markdown and --bundle (below); an
unknown one
prints the usage and exits 1.
How It Works
- Copies
src/todist/, leaving outsrc/partial/(colab-partial fragments already inlined into every page) and any.DS_Store. Fails ifsrc/contains a.env*file, since it would ship as a public URL - Minifies every JS and CSS file
- Content-hashes each JS/CSS filename and rewrites references to it in the HTML and JS (resolved per referencing file, so same-named files in different folders stay distinct)
- Rewrites references to CDN-hosted assets, if the project has an
d8e-asset-manifest.json(see below) - With
--clean-urls, drops.htmlfrom links to pages in the HTML and JS (see below) - Removes the GoatCounter tag on a staging build (see below)
- With
--markdown, writes a Markdown twin beside every indexable page andllms.txtlisting them (see below) - Minifies the HTML
- Obfuscates every JS file (javascript-obfuscator), except
*.min.jslibraries and those that opt out (below). Each file's global helper names get a prefix from its path, so files loaded as classic scripts on one page can't overwrite each other's - With
--bundle, joins the stylesheets and scripts each page loads one after another into fewer files (see below) - Fails a production build if
dist/holds audio, video or any file over 2 MB; a staging build only warns (see below)
Opting a file out of obfuscation
The obfuscator rewrites numbers as expressions and reads strings back through an encoded array. That is free in a script that runs on load, and a real cost in one that runs every frame (a rAF loop, matrix maths, scroll damping). Such a file opts out with a marker on its first line:
// d8e: no-obfuscate — runs every frameIt is still minified and content-hashed like every other file; only the obfuscation step skips it. The marker goes with the minified comments, so nothing of it ships.
A file whose name ends in .min.js (a vendored library: gsap-3.13.0.min.js) is skipped the same way, with no
marker: it is public code with nothing to hide, and obfuscated it is about three times the size and slower to
start. Keep the .min.js name when vendoring a library.
PJAX fragments (--pjax)
A WebGL site navigates by PJAX (see webgl.md): the router fetches the next page's content and swaps it in, so the
canvas, loader and textures survive. d8e --pjax writes, beside every page, a <page>.json the router can fetch:
{ "title": "Products", "view": "<main class=\"page\">…</main>" }title is the page's <title> with entities decoded, ready for document.title; view is its <main>, tag
included, after minification. Both come from the page itself, so there is nothing to keep in sync by hand. A page
without a <main> fails the build.
Clean URLs (--clean-urls)
src/ keeps flat pages (faq.html, not faq/index.html), which any static server serves in dev. d8e --clean-urls
drops .html from every link to a page in dist/, so the deployed site links to /faq:
faq.html->faq,../faq.html#hours->../faq#hours,artists.html?artist=jayda->artists?artist=jaydaindex.html->./,../index.html->../,blog/index.html->blog/- Links are matched like hashed files: relative,
./and root-relative. In JS, strings relative to the site root are matched too, since a URL a script navigates to resolves against the page — solocation.href = "faq.html"and a selector likea[href="faq.html"]keep agreeing with the rewritten HTML. - Absolute links to the site's pages (canonical,
og:url, JSON-LD) are cleaned on a page with a canonical link; its origin is taken as the site's. Links to other hosts, and to files that aren't pages, are left alone. - The sitemap's
<loc>URLs are cleaned the same way, sositemap.xmland the canonicals keep agreeing.
d8e only changes the links. The server must serve faq.html at /faq, and should 301 /faq.html to it: Vercel's
"cleanUrls": true, or in nginx try_files $uri $uri/ $uri.html; plus a redirect from .html keyed on
$request_uri.
Markdown twins and llms.txt (--markdown)
An AI agent reading the site gets more from the page's content than from its design. d8e --markdown writes, beside
every page, a <page>.md with the page's content as Markdown — its <main> and any <aside> outside it (a
project's client, dates and credits beside its hero), in document order: headings, paragraphs, lists, links, images
with alt text, tables, definition lists — and nothing else: no header, nav or footer, no scripts, styles, SVG art,
canvases, media, form controls, or anything aria-hidden. An element whose only content is art takes its
aria-label. A page without an <h1> is headed by its <title>. Each page links
its twin from its <head> (<link rel="alternate" type="text/markdown" href="faq.md">), and dist/llms.txt
(llmstxt.org) lists them all, with each page's title and description, under the site's name
(og:site_name, else the home page's title) and the home page's description:
# Example Co
> One line about the site.
## Pages
- [Home](https://example.com/index.md): One line about the site.
- [FAQ](https://example.com/faq.md): Questions, answered.Twin URLs are absolute when the home page has a canonical link, root-relative otherwise. A noindex page, a
page under a path robots.txt disallows for every agent (User-agent: *), and an experiment
(src/experiment/<name>/, which stands beside the site rather than in it) get no twin and no entry. A page
without a <main> is skipped with a warning.
The server should also answer a request with Accept: text/markdown for a page with its twin, so an agent that
knows to ask gets it without reading the HTML — the website-template's vercel.json and nginx.conf.erb do. The
.md files are plain static files, so nothing breaks without it.
Bundling (--bundle)
A site written as one small file per concern loads twenty stylesheets and as many scripts on a page. d8e --bundle
joins them, in dist/bundle/, without changing what the page does: tags are only joined with the ones straight
after them, in the page's own order.
- Stylesheets: every run of consecutive
<link rel="stylesheet">tags to the site's own files becomes one file per page.url()paths are rewritten for the bundle's folder. CSS is small and blocks rendering, so one request is worth repeating the shared rules on each page. - Scripts: consecutive
<script src>tags are joined, plain with plain anddeferwithdefer, but only scripts that travel together: the same pages load both, one straight after the other on every one of them. So a visitor going from page to page never downloads a script's contents twice, and a script only one page uses stays out of the shared bundles. - Left as they are: a tag with any other attribute (
media,integrity,data-*), a module, anasyncor inline script, anything from a CDN, a stylesheet with an@import, a script that opens with a top-level"use strict", and anything inside<main>. Each of these also ends the run it sits in. - A joined file that nothing else names is deleted, so nothing ships twice.
Two things do change. A script that throws while it loads stops the rest of its bundle, where on its own it only
stopped itself. And document.currentScript inside a bundled file is the bundle's tag.
Tests that run against src/ don't see the bundles. Before relying on --bundle in production, load the built
dist/ once per page and check the console.
CDN-hosted assets (d8e-asset-manifest.json)
If the project root has an d8e-asset-manifest.json, every asset it lists is served from its URL instead of from
dist/:
{
"assets": {
"asset/hero-banner.webp": "https://zone.b-cdn.net/colab-asset-manager/hero-banner.3f2a9c1e.webp"
}
}- Keys are paths under
src/; values are full URLs. - References to the asset in HTML, CSS and JS (relative,
./, root-relative/) are rewritten to the URL. - In JS, paths relative to the site root (
asset/hero.webp) are matched too, since a URL a script sets at runtime resolves against the page rather than the script file. - The local file, if there is one, is left out of
dist/. - An invalid manifest, or a key that points outside
src/, fails the build. - On a page with a canonical link, an absolute URL on the site's own origin (
https://example.com/asset/x.webpin anog:imageor JSON-LD) is rewritten too, so those can name the site and still get the current CDN URL. - A reference to a listed asset that isn't rewritten (
../asset/x.webpfrom a page at the root) fails the build, naming the file and asset: it would ship pointing at a file that isn't deployed.
d8e doesn't care how the manifest was made. c3b-assets writes it (fingerprinting images and syncing them to Bunny); any other key in the file is ignored.
Staging analytics
When D8E_STAGING=1 is set, d8e removes the GoatCounter <script data-goatcounter> tag from every page and says so
in the build output, so staging visits never count toward production's analytics. Any other build leaves the tag
alone.
The host can't tell staging from production — a colab project may put either on Heroku, Vercel or Netlify — so the
project's deploy:staging script sets it for the build, wherever that runs:
- Vercel builds on its own servers:
vercel --prod --build-env D8E_STAGING=1 - Netlify builds on this machine:
D8E_STAGING=1 netlify deploy --build --prod --site <site>-staging
Before 1.9.0, d8e took any Vercel build (VERCEL set) as staging.
Heavy files
A host that bills by bandwidth (Netlify's credits) charges for every byte of every visit, so a 40 MB hero video
left in dist/ costs megabytes per visitor. After everything else, d8e checks dist/ for:
- audio or video (
mp4,webm,mov,m4v,mp3,m4a,ogg,wav), at any size - any other file over 2 MB
and lists each one. A production build fails; a staging build (D8E_STAGING=1) only warns. The fix is to host
the file on the CDN: add it to src/asset/, run c3b-assets u, commit the manifest. A file the manifest lists is
already left out of dist/, so it never trips the check. The limits are fixed, not configurable.
Deploying to npm
- FIRST TIME ONLY: run
npm login - Bump the version in
package.json - Run
npm run deploy
