bun-squeeze
v0.1.3
Published
A chainable build wrapper for Bun, inspired by Laravel Mix.
Maintainers
Readme
Squeeze
A chainable build wrapper for Bun, inspired by Laravel Mix. Fast builds, sensible defaults, granular control when you need it.
Install
bun add -d bun-squeezeQuick Start
// build.ts
import squeeze from 'bun-squeeze';
await squeeze()
.js('js/app.js', 'js/[name]-[hash].js')
.css('css/app.css', 'css/[name]-[hash].css')
.copy('fonts', 'fonts')
.images('img', 'img')
.build();bun build.ts # one-off build
bun build.ts --production # minified, hashed
bun build.ts --watch # rebuild on changeProduction mode is enabled by --production or NODE_ENV=production.
API
squeeze(options?)
Creates a new build instance.
| Option | Default | Description |
|--------|---------|-------------|
| src | 'src' | Source root — all paths are relative to this |
| dist | 'dist' | Output root |
.js(src, dest, options?)
Bundle a JavaScript/TypeScript entrypoint.
squeeze()
.js('js/app.js', 'js/[name]-[hash].js')
.js('js/editor.js', 'js/[name]-[hash].js', { splitting: false })| Option | Default | Description |
|--------|---------|-------------|
| enabled | true | Skip this task when false |
| splitting | true | Code splitting for shared chunks |
| minify | true in production | Minify output |
| sourcemap | 'external' in dev, 'none' in production | Sourcemap mode |
| external | [] | Modules to exclude from the bundle |
| define | {} | Compile-time constants |
| plugins | [] | Bun plugins |
| root | — | Root directory for entrypoint resolution |
.css(src, dest, options?)
Bundle a CSS entrypoint.
squeeze()
.css('css/app.css', 'css/[name]-[hash].css')| Option | Default | Description |
|--------|---------|-------------|
| enabled | true | Skip this task when false |
| minify | true in production | Minify output |
| plugins | [] | Bun plugins (e.g. bun-plugin-tailwind) |
.copy(src, dest, options?)
Copy a directory to the output, preserving structure.
squeeze()
.copy('fonts', 'fonts')| Option | Default | Description |
|--------|---------|-------------|
| enabled | true | Skip this task when false |
.images(src, dest, options?)
Optimise images with sharp. JPEG, PNG, and WebP are compressed; other files are copied as-is.
Requires sharp as a peer dependency: bun add -d sharp
squeeze()
.images('img', 'img', { quality: 90 })| Option | Default | Description |
|--------|---------|-------------|
| enabled | true | Skip this task when false |
| quality | 85 | Quality for JPEG and WebP (1–100) |
| pngCompression | 9 | PNG compression level (0–9) |
.build(options?)
Run all registered tasks and write a manifest file.
await squeeze()
.js('js/app.js', 'js/[name]-[hash].js')
.build({ manifest: 'dist/manifest.json' });| Option | Default | Description |
|--------|---------|-------------|
| manifest | 'dist/manifest.json' | Path to write the asset manifest, or false to disable |
The manifest maps logical filenames to their hashed equivalents:
{
"js/app.js": "js/app-t7epaa3e.js",
"css/app.css": "css/app-r2d1f9k3.css"
}Tailwind CSS
Pass bun-plugin-tailwind as a plugin:
import tailwind from 'bun-plugin-tailwind';
await squeeze()
.css('css/app.css', 'css/[name]-[hash].css', { plugins: [tailwind] })
.build();Licence
MIT
