html-bundle is a primarily zero-config bundler designed for using HTML as Single File Components (SFCs), allowing inline `<style>` and `<script>` elements. It processes HTML, CSS, and TypeScript/JavaScript files from a source directory to a build directory, leveraging tools like ESBuild for bundling and minification, PostCSS for CSS processing, and html-minifier-terser for HTML. The package, currently at version 6.2.3, focuses on developer experience with features like automatic package installation, Hot Module Replacement (HMR) powered by Server-Sent Events and hydro-js, and critical CSS extraction via `beasties`. Its key differentiators include its HTML-first approach to componentization and its integrated tooling for a streamlined development workflow. The project appears actively maintained, though a clear release cadence isn't specified in the provided excerpt.
npm install html-bundleVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `html-bundle` for both development (with HMR) and production builds, including a basic HTML Single File Component structure with inline styles and an optional client-side script using `hydro-js`.
Use a dedicated entry point for HMR-enabled development if `index.html` is complex or serves as a multi-page entry. Ensure development server is configured correctly.
Generate the necessary TLS certificates using a tool like `mkcert` (e.g., `mkcert -install && mkcert localhost`) and place them in the root directory.
Prioritize CLI flags for temporary or environment-specific overrides. For persistent changes, modify `bundle.config.js`. When debugging, check both CLI args and config file.
Add `"jsxFactory": "h"` under `compilerOptions` in your `tsconfig.json` file. Ensure `hydro-js` or a compatible JSX runtime is available.
Ensure your project or script consuming `html-bundle` programmatically is set up for ESM (e.g., `"type": "module"` in `package.json` or using `.mjs` files) and uses `import` statements.
Generate `localhost.pem` and `localhost-key.pem` using `mkcert` (`mkcert -install && mkcert localhost`) and place them in your project's root directory.
Add `"compilerOptions": { "jsxFactory": "h" }` to your `tsconfig.json` to inform TypeScript how to transpile JSX into function calls.Refactor your consuming code to use ES Module `import` syntax. Ensure your environment supports ESM, or use dynamic `import('html-bundle')` if you must remain in a CommonJS file.Verify that your `src` and `build` directories are distinct and do not contain each other. For example, if `src` is `./src`, then `build` should not be `./src/build`.