medusa build
Build your Medusa project for production deployment.Usage
Description
Themedusa build command compiles your Medusa application for production. It performs the following tasks:
- Generates TypeScript types for modules
- Compiles the backend TypeScript code
- Builds the admin dashboard frontend
- Outputs compiled files to the appropriate directories
tsconfig.json file.
Options
--admin-only
Build only the admin dashboard and skip the backend compilation.
- Type:
boolean - Default:
false
- Only the admin frontend is built
- Backend code is not compiled
- Admin is output to
.medusa/admindirectory - Useful when serving the admin separately from the backend
Build Process
1. Type Generation
The build command first generates automated TypeScript types for your modules. These types are placed in the.medusa directory and provide type safety for your Medusa application.
2. Backend Compilation
Unless--admin-only is specified, the build process:
- Loads your
tsconfig.jsonconfiguration - Compiles all TypeScript files in your project
- Outputs compiled JavaScript to the
distdirectory - Preserves your project structure in the output
3. Admin Dashboard Build
The admin dashboard is built using the Medusa admin bundler:- Bundles all admin UI components
- Optimizes assets for production
- Outputs to
.medusa/admindirectory (when using--admin-only) or the standard build directory
Examples
Standard Build
Build both backend and admin for production:Admin-Only Build
Build only the admin dashboard:Build Output
Standard Build
After a standard build, your project structure includes:Admin-Only Build
With--admin-only, only the admin directory is updated:
Build Failures
If the build fails, the command exits with a non-zero exit code:- TypeScript compilation errors: Fix type errors in your code
- Missing tsconfig.json: Ensure your project has a valid TypeScript configuration
- Admin bundler errors: Check admin customizations for errors
Environment Variables
The build command sets:NODE_ENV=development- Set during the build process (types and compilation use development mode)
Integration with Deployment
The build command is typically used in deployment workflows:Example Deployment Script
Docker Example
Performance Tips
Incremental Builds
For faster builds during development, use the development server instead:Build Caching
When deploying, cache yournode_modules and TypeScript build cache to speed up subsequent builds.
Troubleshooting
”Unable to compile application”
This error occurs whentsconfig.json is missing or invalid:
tsconfig.json in your project root.
TypeScript Errors
Build failures due to type errors show detailed error messages:Out of Memory
For large projects, you may need to increase Node.js memory:See Also
- medusa develop - Development server with hot reload
- medusa start - Start production server