Build Command
Bundle your Dwex application for production deployment
Overview
The build command bundles your Dwex application into an optimized production build using Bun's native bundler. It creates a single executable file with minification, tree-shaking, and optional sourcemaps.
Usage
bunx dwex buildFeatures
- Single File Output - Bundles entire application into one file
- Smart Minification - Minifies code while preserving class names for logging
- Tree Shaking - Removes unused code automatically
- Sourcemaps - Optional sourcemap generation for debugging
- Fast Builds - Powered by Bun.build() for maximum speed
Options
--no-minify
Disable minification (useful for debugging production builds):
bunx dwex build --no-minify--sourcemap <type>
Generate sourcemaps. Options: none, inline, external
bunx dwex build --sourcemap inline
bunx dwex build --sourcemap external
bunx dwex build --sourcemap none-o, --outdir <dir>
Specify custom output directory:
bunx dwex build --outdir build
bunx dwex build -o productionDefault Behavior
By default, the build command:
- Reads entry point from
index.ts(ordwex.config.tsif configured) - Bundles to
dist/directory - Minifies syntax and whitespace (keeps class names)
- Generates external sourcemaps
- Targets Bun runtime
Output
After building, you'll see:
✔ Built in 0.45s → 234.56 KB
➜ Output: distRunning Production Build
Run your bundled application:
bun dist/index.jsOr with environment variables:
PORT=8080 bun dist/index.jsExample with All Options
bunx dwex build \
--sourcemap external \
--outdir production \
--no-minifyConfiguration
Customize build behavior in dwex.config.ts:
export default {
entry: "index.ts",
outdir: "dist",
minify: true,
sourcemap: "external",
external: ["some-native-module"],
target: "bun",
};See Configuration for all options.
External Dependencies
Some packages should remain external (not bundled). Specify them in config:
export default {
external: [
"sharp", // Native modules
"sqlite3",
"@prisma/client", // Database clients
],
};Build Performance
The Dwex CLI uses Bun.build() which is extremely fast:
- Small apps (< 100 files): ~100-300ms
- Medium apps (< 500 files): ~300-800ms
- Large apps (> 1000 files): ~1-2s
Troubleshooting
Build Fails
If build fails, check:
- Entry file exists (
index.ts) - All imports are valid
- TypeScript has no errors
Run TypeScript check first:
bun tsc --noEmitLarge Bundle Size
If bundle is too large:
- Mark dependencies as external
- Use dynamic imports for large modules
- Check for duplicate dependencies
Class Names Minified
The CLI preserves class names by default for better logging. If you still see minified names, ensure you're using the latest version:
bun update @dwex/cliNext Steps
- Development Server - Run with hot reload
- Configuration - Customize build options
- Deploying - Deploy your production build