Skip to content

Minimum-Viable-Web/Minibun

Repository files navigation

Minibun - A tiny javascript bundler implementation.

Publish to GitHub Packages Create Release on Version Change GitHub Package License: MIT Zero Dependencies

⚠️ EXPERIMENTAL – See Scope & limitations


Looking for a tiny web development ecosystem? See: Minimum Viable Web


Minibun features:

  • Tree-shaking (TreeShaker)
  • JS Minification (Minifier)
  • CSS Minification (CSSMinifier)
  • HTML Minification (HTMLMinifier)
  • Bundling (Bundler)
  • Module system (ModuleSystem)
  • Obfuscation (Obfuscator)
  • Tokenizing parser (tokenize / findModuleSyntax)

Installation

Install from GitHub Packages:

npm install @minimum-viable-web/minibun

Note: You'll need to authenticate with GitHub Packages. Create a .npmrc file in your project root:

@minimum-viable-web:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN

Or set the GITHUB_TOKEN environment variable. You can create a Personal Access Token with read:packages permission at GitHub Settings > Developer settings > Personal access tokens.

Usage (ESM)

import {
  TreeShaker,
  Minifier,
  CSSMinifier,
  HTMLMinifier,
  Bundler,
  ModuleSystem,
  Obfuscator,
  Pipeline,
} from '@minimum-viable-web/minibun';

CSS Minification

import { CSSMinifier } from '@minimum-viable-web/minibun';

const minifier = new CSSMinifier();
const output = minifier.minifyCSS(`
  /* Main styles */
  .card {
    color: red;
    padding: 10px;
  }
`);
// Output: ".card{color:red;padding:10px}"

The CSSMinifier removes comments, collapses whitespace, strips unnecessary spaces around {}:;,, and removes trailing semicolons — while preserving quoted string literals (e.g. content: "...", url("...")).

Options:

  • keepComments: true — preserve original formatting (no minification)

Pipeline integration:

const pipeline = new Pipeline({ outputFile: '' })
  .withModules(modules)
  .useCSSMinifier();

// Or via JSON config:
Pipeline.fromJSON({ pipeline: { minifyCSS: true } });

HTML Minification

import { HTMLMinifier } from '@minimum-viable-web/minibun';

const minifier = new HTMLMinifier();
const output = minifier.minifyHTML(`
  <!-- page header -->
  <div class="card">
    <p>  hello  </p>
    <input disabled="disabled" />
  </div>
`);
// Output: '<div class=card><p> hello </p><input disabled></div>'

The HTMLMinifier removes comments, collapses whitespace, strips spaces between tags, collapses boolean attributes (disabled="disabled"disabled), removes unnecessary attribute quotes, and removes trailing slashes on void elements — while preserving content inside <pre>, <code>, <textarea>, <script>, and <style> blocks.

Options:

  • keepComments: true — preserve original formatting (no minification)
  • collapseBooleanAttributes: true (default) — shorten boolean attributes
  • collapseAttributeQuotes: true (default) — remove quotes from safe attribute values

Pipeline integration:

const pipeline = new Pipeline({ outputFile: '' })
  .withModules(modules)
  .useHTMLMinifier();

// Or via JSON config:
Pipeline.fromJSON({ pipeline: { minifyHTML: true } });

Development

Build the main bundle:

npm run build

Build all variants (minified, obfuscated, minified+obfuscated):

npm run build:test

Run tests:

npm test

Publishing

This package is published to GitHub Packages. To publish a new version:

  1. Manual Publishing:

    npm login --registry=https://npm.pkg.github.com --scope=@minimum-viable-web
    npm publish
  2. Automated Publishing:

    • Create a GitHub Release, or
    • Use the "Publish to GitHub Packages" workflow from the Actions tab
    • The workflow will automatically build, test, and publish the package

Project Structure

  • src/ - Primary source code (modular, maintainable)
    • Edit files here when making changes
    • Tests import directly from src/ modules
  • dist/ - Generated build artifacts (do not edit directly)
    • minibun.js - Main single-file bundle
    • minibun-min.js - Minified variant
    • minibun-obf.js - Obfuscated variant (hex-encoded strings)
    • minibun-min-obf.js - Minified + obfuscated variant
    • Regenerate with npm run build or npm run build:test

Scope and limitations

  • Algorithms are implemented with a lightweight tokenizer.
  • The tokenizer handles strings, templates, comments, regex literals, and all ES6+ syntax, but there is no full AST — tokens are emitted in sequence without expression parsing.
  • CSS and HTML minification use regex-based approaches (no tokenizer needed) that handle standard CSS/HTML including @-rules, nested blocks, quoted strings, and whitespace-sensitive elements (<pre>, <code>, <textarea>).
  • Suitable for controlled ES6+ codebases with static module structure:
    • Only static import/export with literal specifiers (no import() dynamic imports).
    • No analysis of runtime-evaluated code (eval, new Function(), with).
    • Tree-shaking uses conservative heuristics; modules with detected side effects are preserved.
  • For production builds of arbitrary JavaScript, use established tools (esbuild, Rollup, Terser) instead.

Packages

 
 
 

Contributors