motia build (JavaScript/TypeScript)
Creates an optimized production build of your project.Usage
Options
| Option | Alias | Description | Default |
|---|---|---|---|
--external <packages> | -e | Comma-separated list of external dependencies | [] |
What it does
- Bundles your code - Combines all steps and dependencies into a single file
- Minifies output - Reduces file size for faster deployments
- Tree-shakes unused code - Removes dead code to minimize bundle size
- Generates source maps - Enables error tracking in production
- Targets Node.js 22+ - Optimized for modern Node.js runtimes
Output
dist/index-production.js- Minified production bundledist/index-production.js.map- Source map for debugging
Examples
Basic production build
Build with external dependencies
Keep certain packages external (not bundled):- Deploying to environments that provide certain packages
- Packages have native dependencies that shouldn’t be bundled
- You want to reduce bundle size for packages available in the runtime
Build with environment variables
motia build (Python)
Generates a production-ready Python entrypoint.Usage
Options
| Option | Alias | Description | Default |
|---|---|---|---|
--dir <directory> | -d | Directory containing step files | steps |
--verbose | -v | Enable verbose logging | false |
What it does
- Discovers steps and streams - Finds all
*_step.pyand*_stream.pyfiles - Generates index.py - Creates a production entrypoint at
dist/index.py - Includes imports - Auto-imports all necessary Motia modules
- Registers steps - Sets up step registration code
Output
Generated entrypoint structure
The build command generatesdist/index.py:
Running the production build
Build optimization strategies
JavaScript/TypeScript
Minimize bundle size
- Use external packages for large dependencies:
- Tree-shake unused exports by using named imports:
- Split large steps into smaller modules for better optimization.
Analyze bundle size
Check the build output for size information:- Review dependencies in
package.json - Use
--externalfor packages provided by the runtime - Check for duplicate dependencies with
npm ls
Python
Optimize imports
The generateddist/index.py only imports what’s needed. Keep your steps modular:
Reduce file discovery
Specify the exact directory containing production steps:Deployment
JavaScript/TypeScript deployment
1. Build for production
2. Copy necessary files
3. Deploy the dist directory
Your deployment only needs:dist/index-production.jsdist/index-production.js.mapiii-config.yaml.env(environment-specific)
4. Run in production
Python deployment
1. Build the entrypoint
2. Install dependencies
3. Copy step files
The production build references step files by path, so include them:4. Deploy the dist directory
Your deployment needs:dist/index.pydist/steps/(all step files)iii-config.yaml.env(environment-specific)- Python dependencies
5. Run in production
Build configuration
esbuild settings (JavaScript/TypeScript)
The build uses these esbuild configurations:Customizing builds
To customize the build process, you can create your own build script:motia typegen (Production types)
Generate type definitions for production builds.Usage
Troubleshooting
Build fails with “Cannot find module”
Bundle size too large
- Use
--externalfor large packages - Review and remove unused dependencies
- Check for duplicate packages with
npm dedupe
Python build missing steps
_step.py:
Source maps not working in production
Ensure source maps are deployed alongside the bundle:Import errors in production
ws package is always external. Install it in production:
Continuous Integration
GitHub Actions example
Next steps
Deployment guide
Learn how to deploy your Motia application
Environment variables
Configure environment-specific settings
Monitoring
Monitor your production application
iii configuration
Optimize iii engine settings for production