The Dart
software development kit (SDK) ships with a standalone Dart runtime. This allows Dart code to run in a
command-line interface environment. The SDK includes tools to compile and
package Dart apps. Dart ships with a complete
standard library allowing users to write fully working system apps like custom web servers. Developers can deploy Dart apps in six ways:
Deploying to the web Dart 3 can deploy apps to the web as either JavaScript or WebAssembly apps. Dart supports compiling to WebAssembly .
JavaScript To run in mainstream
web browsers, Dart relies on a
source-to-source compiler to
JavaScript. This makes Dart apps compatible with all major browsers. Dart optimizes the compiled JavaScript output to avoid expensive checks and operations. This results in JavaScript code that can run faster than equivalent code handwritten in plain JavaScript. The first Dart-to-JavaScript compiler was dartc. It was deprecated in Dart 2.0. The second Dart-to-JavaScript compiler was frog. Written in Dart, it was introduced in 2013 and deprecated in 2020. This should not be confused with Dart Frog, an open-source Dart framework for building backend systems from
Very Good Ventures. The third Dart-to-JavaScript compiler is dart2js. Introduced in Dart 2.0, the Dart-based dart2js evolved from earlier compilers. It intended to implement the full Dart language specification and semantics. Developers use this compiler for production builds. It compiles to
minified JavaScript. The fourth Dart-to-JavaScript compiler is dartdevc. Developers could use this compiler for development builds. It compiles to human-readable JavaScript. On March 28, 2013, the Dart team posted an update on their blog addressing Dart code compiled to JavaScript with the dart2js compiler, stating that it now runs faster than handwritten JavaScript on
Chrome's V8 JavaScript engine for the DeltaBlue benchmark. Prior to Dart 2.18, both dart2js and dartdevc could be called from the command line. Dart 2.18 folded these functions into the Dart SDK. This removed the direct command line wrappers but kept the two compilers. The webdev serve command calls the dartdevc compiler. The webdev build command calls the dart2js compiler. The Dart SDK compiles to JavaScript in two ways. To debug code, run webdev serve to compile a larger JavaScript file with human-readable code. Dart-generated JavaScript can be debugged using
Chrome only. $ cd $ webdev serve [--debug] [-o ] To create production apps, run webdev build to compile a minified JavaScript file. $ cd $ webdev build [-o ]
WebAssembly With the Dart 3.22 release, Google announced support for compiling Dart code to
WebAssembly. feature into the Wasm standard. Chrome 119 supports WasmGC.
Firefox 120 and later could support WasmGC, but a current bug is blocking compatibility.
Safari and
Microsoft Edge are integrating WasmGC support.
Deploying to native platforms Dart can compile to native machine code for macOS, Windows, and Linux as command line tools. Dart can compile apps with user interfaces to the web, iOS, Android, macOS, Windows, and Linux using the
Flutter framework.
Self-contained executable Self-contained executables include native machine code compiled from the specified Dart code file, its dependencies, and a small Dart runtime. The runtime handles type checking and garbage collection. The compiler produces output specific to the architecture on which the developer compiled it. This file can be distributed as any other native executable. $ dart compile exe "source.dart" -o "target_app" Generated: $ ./target_app
Ahead-of-time module When
compiled ahead of time, Dart code produces performant and platform-specific modules. It includes all dependent libraries and packages the app needs. This increases its compilation time. The compiler outputs an app specific to the architecture on which it was compiled. $ dart compile aot-snapshot "source.dart" Generated $ dartaotruntime "target_app.aot"
Just-in-time module When
compiled just in time, Dart code produces performant modules that compile fast. This module needs the Dart VM included with the SDK to run. The compiler loads all parsed classes and compiled code into memory the first time the app runs. This speeds up any subsequent run of the app. The compiler outputs an app specific to the architecture on which it was compiled. $ dart compile jit-snapshot "source.dart" Compiling to jit-snapshot file Hello world! $ dart run "target_app.jit" Hello world!
Dart kernel module When compiled as a kernel module, Dart code produces a machine-independent format called the Dart Intermediate Representation (Dart IR). The Dart IR bytecode format can work on any architecture that has a Dart VM. This makes this format very portable and quick to compile, but less performant than other compilation outputs. $ dart compile kernel "source.dart" Compiling to kernel file . $ dart run "target_app.dill" == Concurrency ==