Dart (programming language): Difference between revisions

Content deleted Content added
adding “The latest version of Dart is {{Wikidata|property|reference|edit|Q406009|P348}}.”
m Deploying apps: <syntaxhighlight lang="console">
Line 69:
|JavaScript
|Browser
| {{No}}
| {{No}}
|Slow
|Fast
Line 76:
|WebAssembly<ref name=":3" /><ref name=":2">{{Cite web |last=Thomsen |first=Michael |date=2023-05-10 |title=Announcing Dart 3 |url=https://medium.com/dartlang/announcing-dart-3-53f065a10635 |access-date=2023-05-13 |website=Dart |language=en}}</ref>
|Browser
| {{No}}
| {{No}}
|Slow
|Fast
Line 83:
|Self-contained executable
|macOS, Windows, Linux
| {{Yes}}
| {{No}}
|Slow
|Fast
Line 90:
|Ahead-of-time module
|macOS, Windows, Linux
| {{Yes}}
| {{No}}
|Slow
|Fast
Line 97:
|Just-in-time module
|macOS, Windows, Linux
| {{Yes}}
| {{Yes}}
|Fast
|Slow
Line 104:
|Portable module
|macOS, Windows, Linux
| {{No}}
| {{Yes}}
|Fast
|Slow
Line 121:
:Prior to Dart 2.18, both <code>dart2js</code> and <code>dartdevc</code> 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 <code>webdev serve</code> command calls the <code>dartdevc</code> compiler. The <code>webdev build</code> command calls the <code>dart2js</code> compiler.
:The Dart SDK compiles to JavaScript in two ways.
:To debug code, run <code>webdev serve</code> to compile a larger JavaScript file with human-readable code. Dart-generated JavaScript can be debugged using [[Google Chrome|Chrome]] only.
<syntaxhighlight lang="shelltext">
$ cd <dart_app_directory>
$ webdev serve [--debug] [-o <target.js>]
</syntaxhighlight>To create production apps, run <code>webdev build</code> to compile a minified JavaScript file.<syntaxhighlight lang="shell">
 
<syntaxhighlight lang="text">
</syntaxhighlight>To create production apps, run <code>webdev build</code> to compile a minified JavaScript file.<syntaxhighlight lang="shell">
$ cd <dart_app_directory>
$ webdev build [-o <target.js>]
 
</syntaxhighlight>
 
Line 138:
 
==== 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.
<syntaxhighlight lang="shellconsole">
$ dart compile exe <"source.dart>" -o <"target_app>"
Generated: <target_app>
$ ./<target_app>
</syntaxhighlight>
 
==== Ahead-of-time module ====
:When [[AOT compilation|compiled ahead of time]],<ref>{{Cite web |last=Obinna |first=Onuoha |date=2020-04-07 |title=How does JIT and AOT work in Dart? |url=https://onuoha.medium.com/how-does-jit-and-aot-work-in-dart-cab2f31d9cb5 |access-date=2023-06-20 |website=Medium |language=en}}</ref> 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.
<syntaxhighlight lang="shellconsole">
$ dart compile aot-snapshot <"source.dart>"
Generated <target_app.aot>
$ dartaotruntime <"target_app.aot>"
</syntaxhighlight>
 
==== Just-in-time module ====
:When [[Just-in-time compilation|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.
<syntaxhighlight lang="shellconsole">
$ dart compile jit-snapshot <"source.dart>"
Compiling <source.dart> to jit-snapshot file <target_app.jit>
Hello world!
$ dart run <"target_app.jit>"
Hello world!
</syntaxhighlight>
 
==== 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.
<syntaxhighlight lang="shellconsole">
$ dart compile kernel <"source.dart>"
Compiling <source.dart> to kernel file <target_app>.dill>.
$ dart run <"target_app>.dill"
</syntaxhighlight>