build command creates an optimized production build of your Refine application.
Usage
Options
Specify the platform to run the build command on. The CLI auto-detects your project type, but you can override it.Choices:
vite, nextjs, remix, remix-spa, remix-vite, cracoAdditional arguments passed directly to the underlying build tool
How It Works
Thebuild command:
- Detects your project type (Vite, Next.js, Remix, etc.)
- Runs the appropriate build command for your platform
- Creates optimized production assets
- Outputs build artifacts to the
distorbuilddirectory
Platform-Specific Commands
The CLI runs these commands based on your project type:- Vite:
vite build - Next.js:
next build - Remix:
remix build - Craco:
craco build
Examples
Basic Usage
Build your application:Output
Override Platform
Force a specific platform build:Output
Production Build with Source Maps
For Vite projects:Analyze Bundle Size
For Vite projects with the rollup-plugin-visualizer:Build with Custom Mode
For Vite projects:Build Output
Vite Projects
Build artifacts are output todist/:
Next.js Projects
Build artifacts are output to.next/:
Remix Projects
Build artifacts are output tobuild/:
Package Manager Scripts
Add to yourpackage.json:
package.json
Environment Variables
Set environment-specific variables:.env.production
Optimization
The build command automatically:- Minifies JavaScript and CSS
- Tree-shakes unused code
- Code-splits for optimal loading
- Optimizes assets (images, fonts)
- Generates source maps (if configured)
Common Build Configurations
Vite Build Config
vite.config.ts
Next.js Build Config
next.config.js
After Building
Once your build completes:-
Test the production build locally:
-
Deploy to your hosting provider:
- Vercel, Netlify (for static/SSR)
- AWS, Google Cloud (for custom hosting)
- Docker containers
-
Verify the build:
- Check bundle sizes
- Test all routes
- Verify environment variables
Troubleshooting
Build Fails with Memory Error
Increase Node.js memory limit:Type Errors During Build
For TypeScript projects:Missing Dependencies
Ensure all dependencies are installed:Build is Too Large
- Analyze bundle size
- Remove unused dependencies
- Enable code splitting
- Optimize imports (use tree-shakeable imports)
CI/CD Integration
GitHub Actions
.github/workflows/deploy.yml