Building the Backend
Memos backend is a single Go binary with embedded frontend assets.Development Build
Quick build for testing:Production Build
Optimized build with version information:-s -w- Strip debug symbols (reduces binary size)-X- Set version variable at compile time
Cross-Compilation
Build for different platforms:Building the Frontend
The frontend is a React application built with Vite.Development Build
Build without optimizations:web/dist/
Production Build
Optimized build with minification and code splitting:- Runs Vite in production mode
- Enables minification and tree-shaking
- Outputs to
server/router/frontend/dist/ - Clears previous build artifacts
Build Configuration
Vite configuration (web/vite.config.mts):
Complete Production Build
Build both frontend and backend together:Building with Docker
Official Multi-Stage Dockerfile
Memos uses a multi-stage build for efficiency:Build Docker Image
Multi-Platform Build
Build for multiple architectures using buildx:Build Optimization
Backend Optimizations
Enable CGO for SQLite performance
Enable CGO for SQLite performance
By default, Memos uses pure-Go SQLite (
modernc.org/sqlite). For better performance, build with CGO:Static linking for portability
Static linking for portability
Create fully static binaries:
Profile-guided optimization (PGO)
Profile-guided optimization (PGO)
Go 1.21+ supports PGO. Generate a CPU profile from production, then:
Frontend Optimizations
Analyze bundle size
Analyze bundle size
Generate a bundle analysis:Open the generated report in
web/dist/stats.html.Tree-shaking improvements
Tree-shaking improvements
Vite automatically tree-shakes unused code. Ensure imports are ESM-compatible:
Code splitting strategies
Code splitting strategies
Lazy load heavy components:Configure route-based splitting in
vite.config.mts.CI/CD Builds
Memos uses GitHub Actions for automated builds.Backend Build Workflow
.github/workflows/build-binaries.yml
Docker Build Workflow
.github/workflows/build-stable-image.yml
Build Artifacts
After building, you’ll have:Backend Binary
- Single executable file
- ~40-60 MB (stripped)
- Embeds frontend assets
- Self-contained
Docker Image
- Multi-platform support
- ~60-80 MB compressed
- Alpine-based
- Includes all dependencies
Verifying Builds
Troubleshooting
Frontend assets not embedded
Frontend assets not embedded
Ensure you run
pnpm release (not pnpm build) before building the Go binary.Verify assets exist:Binary size is too large
Binary size is too large
Use linker flags to strip symbols:Compare sizes:
CGO errors on cross-compilation
CGO errors on cross-compilation
Disable CGO for cross-platform builds:
Docker build fails on ARM
Docker build fails on ARM
Use buildx for multi-platform builds:
Next Steps
Testing
Test your builds before deployment
Contributing
Submit your changes upstream