bun-plugin-singlefile
v1.0.0
Published
A Bun plugin to inline JS and CSS into HTML files during build time.
Readme
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-singlefileUsage
import bunSingleFilePlugin from "bun-plugin-singlefile";
await Bun.build({
entrypoints: ["./index.html"],
outdir: "./dist",
plugins: [bunSingleFilePlugin()],
});Options
bunSingleFilePlugin({ inlinePattern? })
inlinePattern: only inlinesrc/hrefvalues matching these glob patterns.- Example:
inlinePattern: ["./main.ts", "./style.css"] - Example:
inlinePattern: ["**/*.{js,ts,css}"]
- Example:
Notes
- Runs on
build.onEndand rewrites emitted.htmloutputs in-place. - Disables code splitting (
build.config.splitting = false) to improve single-file reliability. - External URLs (e.g.
https://,data:,blob:) are never inlined.
