build command creates a production-ready version of the preview app in a .react-email directory and builds it using Next.js.
Usage
Options
Directory containing your email templates. The path is relative to your project root.
Package manager to use for installing dependencies. Supports
npm, yarn, pnpm, and bun.Examples
Basic Usage
Build with default settings:./emails.
Using Yarn
Build with Yarn as the package manager:Using pnpm
Build with pnpm:Custom Email Directory
Build from a custom directory:Combined Options
How It Works
When you runemail build, the CLI performs these steps:
- Validates that the email directory exists
- Deletes any existing
.react-emaildirectory - Copies the preview app from the CLI package to
.react-email - Copies static assets from
emails/staticto.react-email/public/static - Configures Next.js environment variables for your project
- Prepares static site generation (SSG) for all email templates
- Updates package.json scripts for production
- Installs dependencies using your specified package manager
- Runs
next buildto create the production bundle
Build Output
After building, your project structure will include:.react-email directory contains a complete Next.js application ready for deployment or local preview.
Static Site Generation
The build process automatically configures Next.js to pre-render all email templates at build time:- Each template is generated as a static HTML page
- No server-side rendering required at runtime
- Faster page loads in the preview app
- Can be deployed to any static hosting service
Production Configuration
The build command automatically:- Sets
NODE_OPTIONSfor experimental VM modules - Configures TypeScript to ignore build errors
- Sets a 600-second timeout for static page generation
- Marks
esbuildas a server-external package - Removes development-only scripts
Running the Built App
After building, start the production server:.react-email.
Deployment
You can deploy the.react-email directory to any Node.js hosting platform:
Vercel
Netlify
Docker
Create a Dockerfile in.react-email:
Package Manager Detection
If you donβt specify--packageManager, the CLI uses npm by default. To use a different package manager:
Troubleshooting
Build Failures
If the build fails:- Check that all dependencies are installed in your main project
- Ensure your email templates are valid React components
- Review the build logs for specific errors
Out of Memory
For large projects with many templates, you may need to increase Nodeβs memory:Missing Static Files
If static assets arenβt appearing:- Ensure theyβre in
emails/static/directory - Check that the build completed successfully
- Verify files were copied to
.react-email/public/static/
Next Steps
Start Production Server
Learn how to run the built preview app
Export Templates
Export templates as static HTML files