astrolock build
Builds your site for production deployment, creating optimized static files ready to host.
Usage
astrolock build
What It Does
The build command:
- Validates configuration - Checks .astrolock/astrolock.yaml
- Processes content - Converts markdown to HTML
- Generates pages - Creates all routes and pagination
- Optimizes assets - Compresses images, minifies CSS/JS
- Creates search index - Generates
.json/search.json - Builds sitemap - Creates
sitemap.xml - Outputs to dist/ - Final static site ready to deploy
$ astrolock build
Building Astrolock site for production...
✓ Validating configuration
✓ Processing 25 content files
✓ Generating 48 pages
✓ Optimizing 12 images
✓ Building search index
✓ Creating sitemap
Build completed in 8.2s
Output: dist/
Size: 4.2 MB
Pages: 48
Assets: 23
Ready to deploy!All files are output to the dist/ directory:
dist/
├── index.html # Homepage
├── blog/
│ ├── index.html # Blog listing
│ ├── my-post/
│ │ └── index.html # Post page
│ ├── page/2/ # Pagination
│ ├── categories/
│ └── tags/
├── media/mixes/
│ ├── index.html # Collection listing
│ └── summer-mix/
├── about/index.html # Static page
├── assets/ # CSS, JS, fonts
├── audio/ # Copied from public/
├── images/ # Copied from public/
├── video/ # Copied from public/
├── sitemap.xml
├── robots.txt
└── .json/search.json # Search indexWhen to Build
Build your site when:
- Ready to deploy: After finishing content changes
- Testing production: Verify everything works
- Before deploying: Always build fresh before deployment
Build vs Development
| Feature | build (Production) | write (Development) |
|---|---|---|
| Speed | Slower (8-15s) | Faster (3-5s) |
| Optimization | Full | Minimal |
| Minification | Yes | No |
| Image optimization | Yes | No |
| Hot reload | No | Yes |
Tip
Use write while developing, build when deploying.
Images
- Converts to modern formats (WebP, AVIF)
- Generates responsive sizes
- Compresses for web
- Preserves originals in public/
CSS
- Minifies stylesheets
- Removes unused CSS
- Combines files
- Adds vendor prefixes
JavaScript
- Minifies code
- Tree-shakes unused code
- Code splits by route
HTML
- Minifies markup
- Inlines critical CSS
- Preloads fonts and assets
Typical Build Times
| Site Size | Content | Build Time |
|---|---|---|
| Small | <50 posts | 3-5s |
| Medium | 50-200 posts | 8-15s |
| Large | 200-500 posts | 20-40s |
| Very Large | 500+ posts | 60s+ |
Improving Build Speed
- Use incremental builds during development with
astrolock write - Optimize images before adding - Pre-resize large images
- Reduce media file sizes - Use 128-320 kbps for audio
- Limit collection sizes - Archive old content, use pagination
Build Errors
- Frontmatter Error
- Missing Media
- Out of Memory
Error: Invalid frontmatter in content/blog/my-post.md
Line 5: Unexpected tokenFix: Check YAML syntax in frontmatter - quotes, colons, indentation.
Error: Media file not found: public/audio/content/mixes/summer-mix.mp3
Referenced in: content/mixes/summer-mix.mdFix: Add the missing file or fix the frontmatter reference.
Error: JavaScript heap out of memoryFix: Increase Node.js memory:
export NODE_OPTIONS="--max-old-space-size=4096"
astrolock buildError: Invalid frontmatter in content/blog/my-post.md
Line 5: Unexpected tokenFix: Check YAML syntax in frontmatter - quotes, colons, indentation.
Error: Media file not found: public/audio/content/mixes/summer-mix.mp3
Referenced in: content/mixes/summer-mix.mdFix: Add the missing file or fix the frontmatter reference.
Error: JavaScript heap out of memoryFix: Increase Node.js memory:
export NODE_OPTIONS="--max-old-space-size=4096"
astrolock buildPreview Before Deploying
Warning
Always preview your build before deploying to catch issues early.
astrolock build
astrolock preview
# Visit http://localhost:4321
Clean Builds
Sometimes you need a completely clean build:
rm -rf dist/ .json/
astrolock build
Check Build Size
du -sh dist/
# 4.2M dist/
du -sh dist/* | sort -hReduce Build Size
- Compress images before adding to public/
- Use WebP instead of PNG where possible
- Remove unused assets from public/
- Archive old content to a separate directory
- Limit audio quality to 128-192 kbps for samples
GitHub Actions
- name: Build site
run: astrolock build
- name: Upload dist
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/Docker
docker run -v $(pwd):/site astrolock:latest buildExit Codes
- 0: Build succeeded
- 1: Build failed
if astrolock build; then
astrolock deploy
else
echo "Build failed"
exit 1
fiSee Also
- astrolock write - Development server
- astrolock preview - Preview built site
- astrolock deploy - Deploy your site
Tip
Run astrolock build --help for all available options.