{"id":15640,"library":"html-bundle","title":"HTML Bundle","description":"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.","status":"active","version":"6.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/Krutsch/html-bundle","tags":["javascript","bundler","SFC","HTML","TypeScript","esbuild","hydro-js","typescript"],"install":[{"cmd":"npm install html-bundle","lang":"bash","label":"npm"},{"cmd":"yarn add html-bundle","lang":"bash","label":"yarn"},{"cmd":"pnpm add html-bundle","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for Hot Module Replacement (HMR) and JSX support in client-side scripts.","package":"hydro-js","optional":true},{"reason":"Used internally for processing CSS files and inline styles, configurable via postcss.config.js.","package":"postcss","optional":false},{"reason":"Primary bundler for TypeScript/JavaScript, including minification and other optimizations.","package":"esbuild","optional":false},{"reason":"Used for minifying HTML output files.","package":"html-minifier-terser","optional":false},{"reason":"Used for critical CSS extraction and inlining into HTML, enabled via --isCritical flag or config.","package":"beasties","optional":true}],"imports":[{"note":"The programmatic API uses ESM default export. CommonJS `require()` is not supported for this entry point.","wrong":"const router = require('html-bundle');","symbol":"router","correct":"import router from 'html-bundle';"},{"note":"Type import for configuring html-bundle programmatically in TypeScript projects. Requires 'html-bundle' to be installed as a dev dependency.","symbol":"Config","correct":"import type { Config } from 'html-bundle';"},{"note":"The primary interaction is via the `html-bundle` command-line interface, typically defined in `package.json` scripts.","wrong":"node node_modules/html-bundle/dist/cli.js --flag","symbol":"cli","correct":"html-bundle --flag"}],"quickstart":{"code":"{\n  \"name\": \"my-html-project\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"build\": \"html-bundle\",\n    \"dev\": \"html-bundle --hmr --port 3000\"\n  },\n  \"devDependencies\": {\n    \"html-bundle\": \"^6.0.0\"\n  }\n}\n\n// src/index.html\n<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"UTF-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n    <title>My HTML SFC</title>\n    <style>\n      body { font-family: sans-serif; background-color: #f0f0f0; }\n      h1 { color: #333; }\n    </style>\n  </head>\n  <body>\n    <main id=\"app\">\n      <h1>Hello, HTML Bundle!</h1>\n      <script type=\"module\">\n        import { reactive } from 'hydro-js'; // Optional: for reactivity\n        const message = reactive('World');\n        document.querySelector('h1').textContent = `Hello, ${message}!`;\n        console.log('App loaded and script executed.');\n      </script>\n    </main>\n  </body>\n</html>\n\n# Terminal commands to run the project\nnpm install\nnpm run build\nnpm run dev","lang":"typescript","description":"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`."},"warnings":[{"fix":"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.","message":"When using the `--hmr` flag, `html-bundle` generates a development build. This mode is best suited for local development and might not function optimally if triggered from the main `index.html` due to specific HMR injection mechanisms.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Generate the necessary TLS certificates using a tool like `mkcert` (e.g., `mkcert -install && mkcert localhost`) and place them in the root directory.","message":"Enabling secure HTTP2 over HTTPS with the `--secure` flag requires `localhost.pem` and `localhost-key.pem` files to be present in the project's root folder. Without these, the server will fail to start in secure mode.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"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.","message":"Configuration options provided via CLI flags will always override equivalent settings defined in a `bundle.config.js` file. Be aware of this precedence when debugging unexpected build behaviors.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Add `\"jsxFactory\": \"h\"` under `compilerOptions` in your `tsconfig.json` file. Ensure `hydro-js` or a compatible JSX runtime is available.","message":"For TypeScript projects using JSX directly in `<script type=\"module\">` tags or imported components, you must configure `\"jsxFactory\": \"h\"` in your `tsconfig.json` to correctly transpile JSX syntax, especially when integrating with libraries like `hydro-js`.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"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.","message":"Version 6.x of `html-bundle` is primarily designed for ES Modules (ESM) in its programmatic API (e.g., `import router from 'html-bundle';`). Attempting to use CommonJS `require()` syntax for the main programmatic exports will result in errors.","severity":"breaking","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Generate `localhost.pem` and `localhost-key.pem` using `mkcert` (`mkcert -install && mkcert localhost`) and place them in your project's root directory.","cause":"Attempting to run `html-bundle --secure` without the required TLS certificate and key files in the project root.","error":"Error: Missing certificate file 'localhost.pem' or 'localhost-key.pem'"},{"fix":"Add `\"compilerOptions\": { \"jsxFactory\": \"h\" }` to your `tsconfig.json` to inform TypeScript how to transpile JSX into function calls.","cause":"JSX syntax is used in TypeScript files or inline scripts, but the TypeScript compiler or runtime is not configured to handle it correctly, often missing the `jsxFactory` setting.","error":"TypeError: 'createElement' is not a function or 'h' is not defined"},{"fix":"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.","cause":"Attempting to `require('html-bundle')` in a CommonJS context when `html-bundle`'s main entry point is an ES Module.","error":"ERR_REQUIRE_ESM: require() of ES Module html-bundle/dist/index.js from ... not supported."},{"fix":"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`.","cause":"Misconfiguration of `src` or `build` paths in `bundle.config.js` or via CLI, potentially creating a recursive loop where the source directory includes the build directory, or vice-versa, leading to an infinite file globbing/processing loop.","error":"Error: ELOOP: too many symbolic links, stat 'src'"}],"ecosystem":"npm"}