A Babel plugin that compiles htm's tagged template literal syntax (html`...`) into hyperscript calls, React.createElement, Preact h, or plain VNode objects. Version 3.1.1 is current, with a slower release cadence after the major 3.0.0 rework. Unlike JSX, htm uses standard template literals, requiring no build-time syntax changes beyond this plugin. The plugin offers flexible pragma configuration, auto-import options, and experimental outputs like plain objects or monomorphic structures. It integrates with React, Preact, and any hyperscript library and supports features like static subtree caching since v3.
npm install babel-plugin-htmVerified import paths — ran on the pinned version, not inferred.
Shows how to configure babel-plugin-htm with React pragma, use built-ins, fixed arity, and compile a tagged template component.
Add 'import' option to plugin config or manually import htm in your source files.
Set 'pragma' option explicitly to avoid confusion: e.g., `pragma: 'h'` for Preact.
Always ensure your code uses the tagged template with the specified tag, or manually import the pragma function.
Ensure your hyperscript function can handle both rest args and array children. With false, always pass children as array.
Enable @babel/plugin-proposal-object-rest-spread or use preset-env with targets supporting object spread.
Install htm: npm install htm
Either import a hyperscript lib (e.g., import { h } from 'preact') and set pragma: 'h', or use 'import' option to auto-import.Ensure babel-plugin-htm is configured and Babel is transpiling the code, or use htm at runtime without compilation.