This document details the build system and processes across all packages in the spike.land monorepo.
graph TD
Start[Build Process Start]
Clean[Clean Previous Builds]
Types[TypeScript Compilation]
Vite[Vite Build]
Workers[Worker Builds]
Assets[Asset Processing]
Final[Final Output]
Start --> Clean
Clean --> Types
Types --> Vite
Types --> Workers
Vite --> Assets
Workers --> Final
Assets --> Final
# Full build process
yarn build:all # Build everything
yarn build:fe # Build frontend only
yarn build:workers # Build workers only
# Clean builds
yarn clean # Clean all build artifacts
# Type checking
yarn types:check # Check all packages
yarn types:build # Build type declarations
# Development
yarn workspace @spike-npm-land/code dev # Start dev server
yarn workspace @spike-npm-land/code dev:vite # Vite only
yarn workspace @spike-npm-land/code dev:workers # Workers only
# Building
yarn workspace @spike-npm-land/code build # Full build
yarn workspace @spike-npm-land/code build:vite # Vite build
yarn workspace @spike-npm-land/code build:types # TypeScript build
yarn workspace @spike-npm-land/code-worker build # Build worker
yarn workspace @spike-npm-land/code-worker build:worker # Worker-specific build
yarn workspace @spike-npm-land/transpile build # Build transpiler worker
yarn workspace spike-land-renderer build # Build renderer worker
# Remove previous build artifacts
rm -rf packages/*/dist
rm -rf packages/*/dts
rm -rf .tsBuildInfo
// Example tsconfig.json configuration
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"allowJs": true,
"declaration": true,
"declarationDir": "./dts",
"sourceMap": true,
"outDir": "./dist",
"isolatedModules": true,
"strict": true
}
}
// vite.config.ts example
export default defineConfig({
build: {
target: 'esnext',
outDir: 'dist',
rollupOptions: {
external: [...externals],
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
editor: ['monaco-editor']
}
}
}
},
optimizeDeps: {
include: ['react', 'react-dom']
}
});
# wrangler.toml configuration
name = "spike-land"
main = "./src/cf-workers.ts"
compatibility_date = "2024-09-02"
[build]
command = "yarn build"
// ESBuild configuration
const buildOptions = {
entryPoints: ['src/index.ts'],
bundle: true,
format: 'esm',
target: 'es2020',
outfile: 'dist/worker.js'
};
// Asset pipeline configuration
const assetPipeline = {
images: {
// Image optimization
formats: ['webp', 'avif'],
sizes: [640, 1280, 1920]
},
styles: {
// CSS processing
tailwind: true,
autoprefixer: true,
purge: true
}
};
# Environment variables
NODE_ENV=development
VITE_API_URL=http://localhost:8787
# Environment variables
NODE_ENV=test
VITE_API_URL=https://testing.spike.land
# Environment variables
NODE_ENV=production
VITE_API_URL=https://spike.land
// Dynamic imports for route-based code splitting
const Editor = lazy(() => import('./components/Editor'));
const Preview = lazy(() => import('./components/Preview'));
// Build output analysis
import { visualizer } from 'rollup-plugin-visualizer';
export default defineConfig({
plugins: [
visualizer({
filename: 'dist/stats.html',
gzipSize: true
})
]
});
// Asset handling configuration
const assetConfig = {
inlineLimit: 4096, // Inline assets < 4kb
assetsDir: 'assets',
assetFileNames: '[hash][extname]',
chunkFileNames: '[hash].js'
};
# Full type check
yarn types:check
# Generate declarations
yarn types:build
# Run all tests
yarn test
# Test specific package
yarn workspace @spike-npm-land/code test
# Generate bundle analysis
yarn build --analyze
# View stats
open dist/stats.html
# Deploy to development
yarn deploy:dev
# Steps:
1. Build frontend
2. Deploy workers to testing environment
3. Update static assets
# Deploy to production
yarn deploy:prod
# Steps:
1. Run production build
2. Deploy workers to production
3. Update CDN assets
4. Invalidate caches
-
Type Errors
# Clear TypeScript cache rm -rf .tsBuildInfo yarn types:check
-
Bundle Size Issues
# Analyze bundle yarn build --analyze # Review stats.html for large modules
-
Worker Build Failures
# Check Wrangler configuration wrangler deploy --dry-run
Location of important build logs:
- TypeScript:
tsconfig.tsbuildinfo
- Vite:
node_modules/.vite/
- Workers:
.wrangler/