HTML Bundle

6.2.3 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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`.

{
  "name": "my-html-project",
  "version": "1.0.0",
  "scripts": {
    "build": "html-bundle",
    "dev": "html-bundle --hmr --port 3000"
  },
  "devDependencies": {
    "html-bundle": "^6.0.0"
  }
}

// src/index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>My HTML SFC</title>
    <style>
      body { font-family: sans-serif; background-color: #f0f0f0; }
      h1 { color: #333; }
    </style>
  </head>
  <body>
    <main id="app">
      <h1>Hello, HTML Bundle!</h1>
      <script type="module">
        import { reactive } from 'hydro-js'; // Optional: for reactivity
        const message = reactive('World');
        document.querySelector('h1').textContent = `Hello, ${message}!`;
        console.log('App loaded and script executed.');
      </script>
    </main>
  </body>
</html>

# Terminal commands to run the project
npm install
npm run build
npm run dev

view raw JSON →