Build Command
On this page 28
The buddy build command compiles your Stacks application and libraries for production use, optimizing assets for deployment to npm, CDNs, or cloud providers.
Basic Usage
# Interactive build - select what to build
buddy build
# Build specific target
buddy build components
Command Syntax
buddy build [type] [options]
Arguments
| Argument | Description |
|---|---|
type | Optional. Specify build target (components, web-components, functions, views, docs, buddy, cli, stacks, server) |
Options
| Option | Description |
|---|---|
-c, --components | Build your component library |
-w, --web-components | Build your framework-agnostic web component library |
-e, --elements | Alias for --web-components |
-f, --functions | Build your function library |
-p, --views | Build your frontend views |
--pages | Alias for --views |
-d, --docs | Build your documentation site |
-b, --buddy | Build the Buddy binary |
-s, --stacks | Build Stacks framework |
--server | Build the Stacks cloud server (Docker image) |
--project [project] | Target a specific project |
--verbose | Enable verbose output |
Build Targets
Components Library
Build both STX and Web Component libraries:
buddy build:components
# or
buddy prod:components
This creates production-ready component libraries for distribution via npm or CDN.
Web Components
Build framework-agnostic Web Components (Custom Elements):
buddy build:web-components
# or
buddy build:wc
buddy prod:web-components
buddy prod:wc
Functions Library
Build your function library for npm distribution:
buddy build:functions
Frontend Views
Build your frontend for static site generation (SSG):
buddy build:views
Documentation
Build your documentation site:
buddy build:docs
# or
buddy build:documentation
buddy prod:docs
buddy prod:documentation
CLI
Build the Buddy CLI binary:
buddy build:cli
# or
buddy prod:cli
Desktop Application
Build the desktop application with the Craft runtime and compiled Stacks launcher:
buddy build:desktop
# or
buddy prod:desktop
Mobile Applications
Build both native projects, or target one platform while iterating:
buddy build:mobile
buddy build:ios
buddy build:android
# aliases
buddy prod:mobile
buddy prod:ios
buddy prod:android
Server Docker Image
Build the production server Docker image:
buddy build:server
# or
buddy prod:server
buddy build:docker
Stacks Framework
Build the entire Stacks framework (for core developers):
buddy build:stacks
Core Packages
Build core framework packages:
buddy build:core
Production Aliases
Several build:* commands ship a matching prod:* alias (there is no bare prod command):
buddy prod:components # Same as buddy build:components
buddy prod:desktop # Same as buddy build:desktop
buddy prod:mobile # Same as buddy build:mobile
buddy prod:ios # Same as buddy build:ios
buddy prod:android # Same as buddy build:android
buddy prod:web-components # Same as buddy build:web-components
buddy prod:frontend # Same as buddy build:frontend (build:views)
buddy prod:cli # Same as buddy build:cli
buddy prod:server # Same as buddy build:server
buddy prod:docs # Same as buddy build:docs
buddy prod:frontend-static # Same as buddy build:frontend-static
Examples
Build Components with Verbose Output
buddy build:components --verbose
Build Multiple Targets
# Build specific targets sequentially
buddy build:components && buddy build:functions && buddy build:docs
Build for Specific Project
buddy build:views --project my-project
Output Locations
Build outputs are placed in the following locations:
| Target | Output Directory |
|---|---|
| STX Components | dist/stx/ |
| Web Components | dist/web-components/ |
| Functions | dist/functions/ |
| Views | dist/views/ |
| Documentation | dist/docs/ |
| Desktop | dist/desktop/ |
Build Optimization
Stacks automatically applies production optimizations:
- Minification - JavaScript and CSS are minified
- Tree Shaking - Unused code is removed
- Code Splitting - Code is split into optimal chunks
- Asset Optimization - Images and assets are optimized
- Compression - Brotli and gzip compression support
Troubleshooting
Build Fails with Memory Error
For large projects, you may need to increase Node's memory limit:
NODE_OPTIONS="--max-old-space-size=4096" buddy build
TypeScript Errors
If you encounter TypeScript errors during build:
# Run type checking first
buddy test:types
# Fix issues, then rebuild
buddy build
Missing Dependencies
If build fails due to missing dependencies:
buddy install
buddy build
Related Commands
- buddy dev - Development server
- buddy deploy - Deploy to cloud
- buddy test - Run tests