Skip to content

fboldo/bun-plugin-singlefile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bun-plugin-singlefile

Build a single self-contained HTML file by bundling JS/CSS referenced by an HTML entrypoint and inlining the emitted artifacts.

Inspired by vite-plugin-singlefile, adapted for Bun.build().

As the original author notes in the Vite plugin’s “Why” section, a single-file HTML output is usually not a great default for production—but it can be very handy for cases like MCP Apps.

In MCP Apps v1.0.0, Views are delivered as ui:// HTML resources, and the official quickstart recommends bundling the View into a single HTML file. For small apps with no external assets (and ideally no external network calls), this is often the simplest approach because it minimizes CSP metadata and streamlines build and delivery

Install

bun add bun-plugin-singlefile

Usage

import bunSingleFilePlugin from "bun-plugin-singlefile";

await Bun.build({
  entrypoints: ["./index.html"],
  outdir: "./dist",
  plugins: [bunSingleFilePlugin()],
});

Options

bunSingleFilePlugin({ inlinePattern? })

  • inlinePattern: only inline src/href values matching these glob patterns.
    • Example: inlinePattern: ["./main.ts", "./style.css"]
    • Example: inlinePattern: ["**/*.{js,ts,css}"]

Notes

  • Runs on build.onEnd and rewrites emitted .html outputs in-place.
  • Disables code splitting (build.config.splitting = false) to improve single-file reliability.
  • External URLs (e.g. https://, data:, blob:) are never inlined.

About

Build a single self-contained HTML file by bundling JS/CSS referenced by an HTML entrypoint and inlining the emitted artifacts.

Resources

Stars

Watchers

Forks

Contributors