commandkit build command creates an optimized production bundle of your Discord bot, ready for deployment.
Basic Usage
Build your bot for production:- Run TypeScript type checking
- Bundle your code with optimizations
- Output to the
dist/directory (configurable) - Generate source maps (configurable)
- Copy locale files if present
Production builds are optimized for performance with minification and tree-shaking.
Command Options
Custom Config Path
Specify a custom config file:Build Output
By default, production builds are written todist/ directory:
Entry Point Generation
The CLI automatically generates an optimized entry point (dist/index.js) that:
- Loads environment variables
- Imports Discord.js and CommandKit
- Bootstraps your application
- Handles initialization errors
Configuration Options
Customize the build in yourcommandkit.js config:
Output Directory
Source Maps
Control source map generation:- With Source Maps
- Without Source Maps
- Better error stack traces
- Easier debugging
- Slightly larger bundle size
Disable Chunking
Control code splitting:Chunking is enabled by default in production to optimize bundle size through code splitting.
Anti-Crash Script
Control whether to include the anti-crash monitor:TypeScript Type Checking
Production builds include full TypeScript type checking by default:Disable Type Checking
If you want to skip type checking:Environment Variables
Production builds automatically load:Public Variables
Variables prefixed withCOMMANDKIT_PUBLIC_ are embedded in the bundle:
Custom Entry Points
Add additional entry points to the build:Compiler Plugins
Extend the build process with compiler plugins:Advanced Configuration
Custom Rolldown Options
Access the underlying bundler configuration:Custom Rolldown Plugins
Add Rolldown plugins directly:Running the Production Build
After building, start your bot:- Using start command
- Direct execution
- Validates build exists
- Respects config file settings
- Consistent with development workflow
Sharding Support
If you have a sharding manager, the CLI will automatically use it:If
sharding-manager.js exists in the output directory, it will be used as the entry point instead of index.js.Build Performance
Production builds are optimized for output quality:- Small project (under 50 files): ~2-5 seconds
- Medium project (50-200 files): ~5-15 seconds
- Large project (over 200 files): ~15-30 seconds
Deployment Checklist
Continuous Integration
Example GitHub Actions workflow:Troubleshooting
Build fails with type errors
Build fails with type errors
If the build fails due to TypeScript errors:
- Fix the type errors in your code
- Or temporarily disable type checking:
- Run
tsc --noEmitseparately to check types
Missing modules in production
Missing modules in production
If modules are missing when running the build:
- Ensure all dependencies are in
dependencies, notdevDependencies - Check that
node_modules/is included in your deployment - Run
npm cion the server to install dependencies
Environment variables not loading
Environment variables not loading
If environment variables aren’t working:
- Ensure
.env.productionexists - Check that variable names are correct
- Remember: only
COMMANDKIT_PUBLIC_*vars are embedded - Other vars must be present at runtime
Build output too large
Build output too large
If your build is too large:
- Enable chunking (default behavior)
- Disable source maps for production
- Check for accidentally bundled dev dependencies
- Use
skipNodeModulesBundlefor native modules
Next Steps
Development Mode
Return to development with hot reloading
Code Generators
Generate commands and events