DartDevCompiler (DDC)
The DartDevCompiler (DDC) is the development compiler for Dart web applications. It produces modular JavaScript output that supports fast incremental compilation during development.
Overview
DDC is the default compiler used by build_runner during development. It is
optimized for fast edit-refresh cycles rather than production performance.
For production builds, use dart2js which produces optimized, minified output.
How It Works
DDC compiles each Dart library into a separate JavaScript module. This enables:
- Fast incremental compilation - Only recompile changed files
- Modular output - Each library is a separate module
- Source maps - Debug Dart code directly in the browser
- Hot reload - Fast development iteration
Configuration
DDC is configured through build.yaml:
targets:
$default:
builders:
build_web_compilers|entrypoint:
generate_for:
- web/main.dart
options:
compiler: dartdevc
Development Server
Use build_runner serve for development:
dart run build_runner serve
This starts a development server with:
- DDC compilation
- Incremental rebuilds on file changes
- Live reload in the browser
Production Builds
For production, switch to dart2js:
dart run build_runner build --release
Or configure in build.yaml:
targets:
$default:
builders:
build_web_compilers|entrypoint:
options:
compiler: dart2js
dart2js_args:
- -O4
- --minify
Differences from dart2js
| Feature | DDC | dart2js |
|---|---|---|
| Compilation speed | Fast | Slow |
| Output size | Large | Small (minified) |
| Incremental | Yes | No |
| Source maps | Full | Limited |
| Tree shaking | No | Yes |
| Production ready | No | Yes |
Troubleshooting
Module not found errors
If you see module loading errors, ensure all dependencies are properly declared
in your pubspec.yaml.
Slow compilation
- Check for circular dependencies
- Reduce the number of entry points
- Use
--delete-conflicting-outputsflag
Source maps not working
- Ensure
--enable-assertsis not interfering - Check browser DevTools settings
- Clear browser cache