Skip to content

v4.0.0 - Templates API

Latest

Choose a tag to compare

@localnerve localnerve released this 11 Sep 16:30
· 8 commits to main since this release
71b6bae

v4.0.0

Breaking changes

  • templates is now the API. The flat htmlPath / jsReplacement options are
    removed; passing either throws a migration error. Describe html via
    templates: [{ name, htmlPath, token }]. Pure-JS and pure-CSS builds pass no
    templates. See docs/v4.0.0.md for the full migration guide.
  • HTML outputs are a named map. The result now exposes html[name] (each
    { name, path, getHtml }) keyed by template name. The v3.5.0 htmls[] array and
    the getHtml() / htmlPath shorthands are removed.
  • Per-template CSS overrides. A template may supply its own cssPath (and
    cssLinkHref), falling back to the shared top-level values. The shared cssPath
    remains the canonical output css file.
  • Explicit outputDir validation. build() now throws upfront when outputDir
    does not exist or is not a directory, instead of failing with ENOENT on the first
    write. The library still never creates or cleans directories — that stays the
    caller's responsibility.
  • Documented constraint: tokens must be unique in the source file. The injector
    replaces the first occurrence of each token; a token string also present in a comment
    or other literal redirects injection there.

Unchanged from v3.5.0

  • Syntax-aware (acorn) injection: markup is spliced into the token's string/template
    literal with escaping for that quote context — safe with quotes, backticks, ${,
    and backslashes in the payload.
  • Output-filename collision detection (duplicate resolved names throw).
  • Multi-template support; shared css/link are embedded in the first template that uses them by default (sharedMultiTemplate: "first"), or in every template with sharedMultiTemplate: "every".

Migration example

 const result = await build(outputDir, {
   jsPath: '/…/component.js',
   cssPath: '/…/component.css',
-  htmlPath: '/…/index.html',
-  jsReplacement: '__JS_REPLACEMENT__'
+  templates: [
+    { name: 'index', htmlPath: '/…/index.html', token: '__JS_REPLACEMENT__' }
+  ]
 });

-await result.getHtml();
+await result.html.index.getHtml();

What's Changed

Full Changelog: v3.5.1...v4.0.0