dart-compilation-deployment
Original:🇺🇸 English
Translated
Compile and deploy Dart apps for various native and web target platforms.
7installs
Sourcedart-lang/skills
Added on
NPX Install
npx skill4agent add dart-lang/skills dart-compilation-deploymentTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →dart-compilation
Goal
Compiles Dart source code into optimized, target-specific formats including self-contained native executables, ahead-of-time (AOT) snapshots, just-in-time (JIT) modules, and web-deployable JavaScript or WebAssembly. Assumes the Dart SDK is installed, the target environment is configured, and the source code does not rely on unsupported libraries (e.g., ) for native compilation.
dart:mirrorsDecision Logic
Use the following logic to determine the appropriate compilation target:
- Is the target a Web environment?
- Yes -> Use (or
dart compile js). See Related Skill:dart compile wasm.dart-web-development
- Yes -> Use
- Is the target a Native OS (Windows, macOS, Linux)?
- Does the deployment require a single, self-contained binary?
- Yes -> Use .
dart compile exe
- Yes -> Use
- Is the deployment environment resource-constrained (e.g., embedded systems, containers) where multiple apps share a runtime?
- Yes -> Use and execute with
dart compile aot-snapshot.dartaotruntime
- Yes -> Use
- Does the application benefit from profile-guided optimization via a training run?
- Yes -> Use .
dart compile jit-snapshot
- Yes -> Use
- Does the deployment require a single, self-contained binary?
- Is the target platform-agnostic?
- Yes -> Use to generate a portable
dart compile kernelfile..dill
- Yes -> Use
Instructions
-
Determine Compilation Target and Parameters Evaluate the project requirements against the Decision Logic. STOP AND ASK THE USER: "Which target platform and architecture are you compiling for? Do you require cross-compilation (e.g., compiling for Linux ARM64 from macOS)?"
-
Compile to Self-Contained Executable (Native) For standard native binaries, use thesubcommand. This bundles the machine code and a minimal Dart runtime.
exebashdart compile exe bin/main.dart -o build/app.exeCross-Compilation (Linux targets only):bashdart compile exe \ --target-os=linux \ --target-arch=arm64 \ bin/main.dart -o build/app_linux_arm64 -
Compile to AOT Snapshot (Resource-Constrained) For environments where disk space is limited and a shared runtime is preferred, generate an AOT snapshot.bash
dart compile aot-snapshot bin/main.dart -o build/app.aotExecution:bashdartaotruntime build/app.aot -
Compile to Web Targets (JS / Wasm) For web deployments, compile to optimized JavaScript or WebAssembly.bash
# Compile to JS with aggressive optimizations (O2 is safe, O3/O4 omit type checks) dart compile js -O2 -o build/app.js web/main.dart # Compile to WebAssembly dart compile wasm web/main.dart -o build/app.wasm -
Compile to JIT or Kernel Modules (Specialized) JIT Snapshot (requires a training run):bash
dart compile jit-snapshot bin/main.dart -o build/app.jit dart run build/app.jitPortable Kernel:bashdart compile kernel bin/main.dart -o build/app.dill dart run build/app.dill -
Validate-and-Fix Loop After executing the compilation command, verify the output file exists and test its execution.bash
# Verify file generation ls -la build/ # Test execution (example for exe) ./build/app.exeError Handling: If compilation fails due to build hooks, fallback to. If type errors occur in JS compilation atdart buildor-O3, downgrade to-O4and recompile.-O2
Constraints
- DO NOT use or
dart compile exeif the package or its dependencies utilize build hooks; these commands will fail. Usedart compile aot-snapshotinstead.dart build - DO NOT use or
dart:mirrorsin code targeted fordart:developerorexecompilation.aot-snapshot - DO use for self-contained native binaries on Windows/macOS/Linux.
dart compile exe - DO use or
dart compile jsfor web deployment targets.dart compile wasm - DO optimize for performance using AOT compilation where supported.
- DO use for running AOT snapshots in resource-constrained environments.
dartaotruntime - DO NOT attempt cross-compilation for target operating systems other than Linux.
- DO NOT use or
-O3JavaScript optimizations without verifying that the application never throws a subtype of-O4(e.g.,Error) and handles edge-case user input safely.TypeError