An esbuild plugin that enables loading HTML files as ES modules, following the WICG HTML Modules proposal. Version 0.9.1 allows importing HTML files with `import` statements, where the HTML template becomes the default export and `<script type="module">` code runs as the module script. Supports configuration for global CSS extraction, local style transformation via PostCSS, and custom file filters. Key differentiator: enables web component authors to co-locate templates, scripts, and styles in single HTML files with standard ES module semantics. Released weekly, actively maintained.
npm install esbuild-plugin-html-modulesNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to set up esbuild with htmlModulesPlugin, including global style extraction and local style transformation with PostCSS.
Replace `extractScopedStyles: true` with `extractGlobalStyles: true` and use standard CSS nesting or `@scope` for scoped styles.
Use `import { htmlModulesPlugin } from 'esbuild-plugin-html-modules'` instead of the default import.Use `const htmlModulesPlugin = require('esbuild-plugin-html-modules').default;`Use a RegExp, e.g., `filter: /\.html$/`.
Run `npm install esbuild-plugin-html-modules --save-dev`.
Change to `const htmlModulesPlugin = require('esbuild-plugin-html-modules').default;`