build
Builds the application for production.
Usage
bash
bun ereo build [options]Or via package.json:
json
{
"scripts": {
"build": "ereo build"
}
}bash
bun run buildOptions
| Option | Description | Default |
|---|---|---|
--outDir | Output directory | .ereo |
--minify | Minify output (true or false) | true |
--sourcemap | Generate source maps (true or false) | true |
Examples
Basic Build
bash
# Build with defaults (output to .ereo/, minified, with sourcemaps)
bun ereo build
# Custom output directory
bun ereo build --outDir dist
# Disable source maps
bun ereo build --sourcemap=false
# Disable minification (for debugging)
bun ereo build --minify=false
# Production build with all optimizations
bun ereo build --outDir dist --minify --sourcemap=falseOutput Structure
.ereo/
├── server/
│ └── index.js # Server bundle
├── client/
│ ├── index.js # Client entry
│ ├── islands/ # Island bundles
│ │ ├── Counter.js
│ │ └── SearchBox.js
│ └── chunks/ # Shared chunks
│ ├── react.js
│ └── vendor.js
└── static/
├── styles.css # Compiled CSS
└── public/ # Static assetsBuild Process
- Type checking - Validates TypeScript
- Route discovery - Finds all routes
- Server bundle - Compiles server code
- Client bundle - Compiles client code
- Island extraction - Creates island bundles
- Asset processing - Optimizes static assets
- Manifest generation - Creates asset manifest
Configuration
Configure build in ereo.config.ts:
ts
import { defineConfig } from '@ereo/core'
export default defineConfig({
build: {
// Deployment target
target: 'bun', // 'bun' | 'node' | 'cloudflare' | 'deno'
// Output directory
outDir: '.ereo',
// Minification
minify: true,
// Source maps
sourcemap: true, // true | false
// Code splitting
splitting: true,
// External packages (not bundled)
external: ['sharp', 'sqlite3']
}
})Environment Variables
Build-time environment:
bash
# Production build
NODE_ENV=production bun ereo build
# Custom environment
NODE_ENV=staging bun ereo buildEnvironment files loaded:
.env.env.local.env.production.env.production.local
Static Generation
For SSG routes, pages are pre-rendered:
ts
// routes/posts/[slug].tsx
export const config = {
render: 'ssg'
}
export async function getStaticPaths() {
const posts = await db.posts.findMany()
return posts.map(post => ({
params: { slug: post.slug }
}))
}Build output includes static HTML:
dist/
└── static/
└── posts/
├── hello-world.html
├── getting-started.html
└── advanced-guide.htmlProgrammatic Usage
ts
import { build } from '@ereo/cli'
await build({
outDir: 'dist',
minify: true,
sourcemap: false
})Build Analysis
Bundle Size
After build, check bundle sizes:
bash
ls -lh dist/client/Visualization
Generate bundle analysis:
bash
bun ereo build --analyzeOpens interactive bundle visualization in browser.
Optimization Tips
Code Splitting
EreoJS automatically splits:
- Each route into separate chunks
- Each island into separate bundles
- Shared dependencies into common chunks
Tree Shaking
Unused exports are removed. Ensure:
- Use ES modules (
import/export) - Avoid side effects in modules
- Mark packages as side-effect-free in
package.json
External Dependencies
For server-only packages:
ts
// ereo.config.ts
export default defineConfig({
build: {
external: ['sharp', 'bcrypt', 'sqlite3']
}
})Troubleshooting
Build Errors
bash
# Verbose output
DEBUG=ereo:* bun ereo build
# Skip type checking
bun ereo build --skipTypeCheckLarge Bundle Size
- Check for unnecessary dependencies
- Use dynamic imports for large modules
- Analyze bundle with
--analyze
Memory Issues
For large projects:
bash
# Increase memory limit
NODE_OPTIONS="--max-old-space-size=8192" bun ereo build