Environment-based Build System Implementation

Summary

Implemented a robust environment-based build system to handle different deployment scenarios (LocalSiteOnly, LocalMonorepo, Vercel, Railway) with proper content path resolution and environment variable management.

Why Care

A reliable build system that works consistently across different environments is crucial for:
  • Developer experience
  • Deployment reliability
  • Content management
  • Team collaboration

Changes

Added

  • New envUtils.js module for centralized environment variable management
  • Content path resolution based on DEPLOY_ENV environment variable
  • Comprehensive environment configuration with proper fallbacks
  • Logging for environment configuration and content path resolution

Modified

  • Updated build script in package.json to properly load environment variables
  • Enhanced content.config.ts to use the new environment utilities
  • Added environment variable type definitions in env.d.ts
  • Created/updated .env and .env.example files with documentation

Fixed

  • Resolved content path resolution issues across different environments
  • Fixed environment variable loading order and precedence
  • Addressed potential race conditions in environment setup

Technical Details

Environment Variables

  • NODE_ENV: Node.js environment (development/production)
  • APP_ENV: Application environment (matches NODE_ENV if not set)
  • DEPLOY_ENV: Deployment environment (LocalSiteOnly, LocalMonorepo, Vercel, Railway)

Supported Deployment Environments

  1. LocalSiteOnly: Development with content in src/generated-content
  2. LocalMonorepo: Development within the monorepo structure
  3. Vercel: Production deployment on Vercel
  4. Railway: Production deployment on Railway

Testing

To verify the setup:
bash
# Test LocalSiteOnly
DEPLOY_ENV=LocalSiteOnly pnpm build

# Test LocalMonorepo
DEPLOY_ENV=LocalMonorepo pnpm build

Documentation

See Maintain an Environment-based Build System for detailed documentation.