CINXE.COM

dart compile | Dart

<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><script>!function(e,t,a,n){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var g=t.getElementsByTagName(a)[0],m=t.createElement(a);m.async=!0,m.src="https://www.googletagmanager.com/gtm.js?id=GTM-5VSZM5J",g.parentNode.insertBefore(m,g)}(window,document,"script","dataLayer")</script><meta name="description" content="Command-line tool for compiling Dart source code."><title>dart compile | Dart</title><link rel="icon" sizes="64x64" href="/assets/img/logo/dart-64.png" eleventy:ignore><link href="/assets/img/touch-icon-iphone.png" rel="apple-touch-icon" eleventy:ignore><link href="/assets/img/touch-icon-ipad.png" rel="apple-touch-icon" sizes="152x152" eleventy:ignore><link href="/assets/img/touch-icon-iphone-retina.png" rel="apple-touch-icon" sizes="180x180" eleventy:ignore><link href="/assets/img/touch-icon-ipad-retina.png" rel="apple-touch-icon" sizes="167x167" eleventy:ignore><meta name="twitter:card" content="summary"><meta name="twitter:site" content="@dart_lang"><meta name="twitter:title" content="dart compile"><meta name="twitter:description" content="Command-line tool for compiling Dart source code."><meta property="og:title" content="dart compile"><meta property="og:description" content="Command-line tool for compiling Dart source code."><meta property="og:url" content="/tools/dart-compile/"><meta property="og:image" content="/assets/img/logo/dart-logo-for-shares.png?2" eleventy:ignore><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Display:wght@400&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Mono:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0..1,0" rel="stylesheet"><link rel="stylesheet" href="/assets/css/main.css?v=3"><script src="/assets/js/os-tabs.js?v=3"></script><script src="/assets/js/main.js?v=3"></script><script>!function(e,a,t,n,c,o,s){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,o=a.createElement(t),s=a.getElementsByTagName(t)[0],o.async=1,o.src="//www.google-analytics.com/analytics.js",s.parentNode.insertBefore(o,s)}(window,document,"script",0,"ga"),ga("create","UA-26406144-4","auto"),ga("send","pageview")</script></head><body class="default.html"><a id="skip-to-main" class="filled-button" href="#site-content-title" tabindex="1">Skip to main content</a><section id="cookie-notice"><div class="container"><p>dart.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.</p><div class="button-group"><a class="text-button" href="https://policies.google.com/technologies/cookies" target="_blank" rel="noopener">Learn more</a> <button id="cookie-consent" class="filled-button">OK, got it</button></div></div></section><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5VSZM5J" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><div id="site-banner" role="alert"><p>Announcing Dart 3.7! Find out about updates to the language, analyzer, pub.dev, and more, in the <a href="https://medium.com/dartlang/announcing-dart-3-7-bf864a1b195c" target="_blank">blog post</a>.</p></div><header id="site-header"><nav id="mainnav"><div id="menu-toggle"><span class="material-symbols" title="Toggle side navigation menu." aria-label="Toggle side navigation menu." type="button">menu</span></div><a href="/" class="brand" title="Dart"><img src="/assets/img/logo/logo-white-text.svg" alt="Dart"></a><ul class="navbar"><li><a href="/overview" class="nav-link">Overview</a></li><li class="mainnav__get-started"><a href="/docs" class="nav-link active"><span>Docs</span></a></li><li><a href="/community" class="nav-link">Community</a></li><li><a href="/#try-dart" class="nav-link">Try Dart</a></li><li><a href="/get-dart" class="nav-link">Get Dart</a></li><li class="searchfield"><form action="/search" class="site-header-search form-inline" id="cse-search-box"><input type="hidden" name="cx" value="011220921317074318178:_yy-tmb5t_i"> <input type="hidden" name="ie" value="UTF-8"> <input type="hidden" name="hl" value="en"> <input class="site-header-searchfield form-control search-field" type="search" name="q" id="search-main" autocomplete="off" placeholder="Search" aria-label="Search"></form></li></ul></nav></header><div id="site-below-header"><div id="site-main-row"><div id="sidenav"><form action="/search/" class="site-header-search form-inline"><input class="site-header-searchfield form-control search-field" type="search" name="q" id="search-side" autocomplete="off" placeholder="Search" aria-label="Search"></form><ul class="navbar-nav"><li aria-hidden="true"><div class="sidenav-divider"></div></li><li class="nav-item"><a href="/overview" class="nav-link">Overview</a></li><li class="nav-item"><a href="/community" class="nav-link">Community</a></li><li class="nav-item"><a href="https://dartpad.dev" class="nav-link">Try Dart</a></li><li class="nav-item"><a href="/get-dart" class="nav-link">Get Dart</a></li><li class="nav-item"><a href="/docs" class="nav-link">Docs</a></li><li aria-hidden="true"><div class="sidenav-divider"></div></li></ul><ul class="nav"><li class="nav-item"><button class="nav-link collapsed collapsible" data-toggle="collapse" data-target="#-sidenav-1" role="button" aria-expanded="false" aria-controls="-sidenav-1"><span>Language</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1"><li class="nav-item"><a class="nav-link" href="/language"><div><span>Introduction</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-1-2" role="button" aria-expanded="false" aria-controls="-sidenav-1-2"><span>Syntax basics</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1-2"><li class="nav-item"><a class="nav-link" href="/language/variables"><div><span>Variables</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/operators"><div><span>Operators</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/comments"><div><span>Comments</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/metadata"><div><span>Metadata</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/libraries"><div><span>Libraries & imports</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/keywords"><div><span>Keywords</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-1-3" role="button" aria-expanded="false" aria-controls="-sidenav-1-3"><span>Types</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1-3"><li class="nav-item"><a class="nav-link" href="/language/built-in-types"><div><span>Built-in types</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/records"><div><span>Records</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/collections"><div><span>Collections</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/generics"><div><span>Generics</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/typedefs"><div><span>Typedefs</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/type-system"><div><span>Type system</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-1-4" role="button" aria-expanded="false" aria-controls="-sidenav-1-4"><span>Patterns</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1-4"><li class="nav-item"><a class="nav-link" href="/language/patterns"><div><span>Overview & usage</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/pattern-types"><div><span>Pattern types</span></div></a></li><li class="nav-item"><a class="nav-link" href="https://codelabs.developers.google.com/codelabs/dart-patterns-records" target="_blank" rel="noopener"><div><span>Applied tutorial</span><span class="material-symbols" aria-hidden="true">open_in_new</span></div></a></li></ul></li><li class="nav-item"><a class="nav-link" href="/language/functions"><div><span>Functions</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-1-6" role="button" aria-expanded="false" aria-controls="-sidenav-1-6"><span>Control flow</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1-6"><li class="nav-item"><a class="nav-link" href="/language/loops"><div><span>Loops</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/branches"><div><span>Branches</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/error-handling"><div><span>Error handling</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-1-7" role="button" aria-expanded="false" aria-controls="-sidenav-1-7"><span>Classes & objects</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1-7"><li class="nav-item"><a class="nav-link" href="/language/classes"><div><span>Classes</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/constructors"><div><span>Constructors</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/methods"><div><span>Methods</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/extend"><div><span>Extend a class</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/mixins"><div><span>Mixins</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/enums"><div><span>Enums</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/extension-methods"><div><span>Extension methods</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/extension-types"><div><span>Extension types</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/callable-objects"><div><span>Callable objects</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-1-8" role="button" aria-expanded="false" aria-controls="-sidenav-1-8"><span>Class modifiers</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1-8"><li class="nav-item"><a class="nav-link" href="/language/class-modifiers"><div><span>Overview & usage</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/class-modifiers-for-apis"><div><span>Class modifiers for API maintainers</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/modifier-reference"><div><span>Reference</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-1-9" role="button" aria-expanded="false" aria-controls="-sidenav-1-9"><span>Concurrency</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1-9"><li class="nav-item"><a class="nav-link" href="/language/concurrency"><div><span>Overview</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/async"><div><span>Asynchronous support</span></div></a></li><li class="nav-item"><a class="nav-link" href="/language/isolates"><div><span>Isolates</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-1-10" role="button" aria-expanded="false" aria-controls="-sidenav-1-10"><span>Null safety</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-1-10"><li class="nav-item"><a class="nav-link" href="/null-safety"><div><span>Sound null safety</span></div></a></li><li class="nav-item"><a class="nav-link" href="/null-safety/migration-guide"><div><span>Migrating to null safety</span></div></a></li><li class="nav-item"><a class="nav-link" href="/null-safety/understanding-null-safety"><div><span>Understanding null safety</span></div></a></li><li class="nav-item"><a class="nav-link" href="/null-safety/unsound-null-safety"><div><span>Unsound null safety</span></div></a></li><li class="nav-item"><a class="nav-link" href="/null-safety/faq"><div><span>FAQ</span></div></a></li></ul></li></ul></li><li class="nav-item"><button class="nav-link collapsed collapsible" data-toggle="collapse" data-target="#-sidenav-2" role="button" aria-expanded="false" aria-controls="-sidenav-2"><span>Core libraries</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-2"><li class="nav-item"><a class="nav-link" href="/libraries"><div><span>Overview</span></div></a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-core"><div><span>dart:core</span></div></a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-async"><div><span>dart:async</span></div></a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-math"><div><span>dart:math</span></div></a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-convert"><div><span>dart:convert</span></div></a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-io"><div><span>dart:io</span></div></a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop"><div><span>dart:js_interop</span></div></a></li><div class="sidenav-divider"></div><li class="nav-item"><a class="nav-link" href="/libraries/collections/iterables"><div><span>Iterable collections</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-2-10" role="button" aria-expanded="false" aria-controls="-sidenav-2-10"><span>Asynchronous programming</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-2-10"><li class="nav-item"><a class="nav-link" href="/libraries/async/async-await"><div><span>Tutorial</span></div></a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/futures-error-handling"><div><span>Futures and error handling</span></div></a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/using-streams"><div><span>Using streams</span></div></a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/creating-streams"><div><span>Creating streams</span></div></a></li></ul></li></ul></li><li class="nav-item"><button class="nav-link collapsed collapsible" data-toggle="collapse" data-target="#-sidenav-3" role="button" aria-expanded="false" aria-controls="-sidenav-3"><span>Effective Dart</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-3"><li class="nav-item"><a class="nav-link" href="/effective-dart"><div><span>Overview</span></div></a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/style"><div><span>Style</span></div></a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/documentation"><div><span>Documentation</span></div></a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/usage"><div><span>Usage</span></div></a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/design"><div><span>Design</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsed collapsible" data-toggle="collapse" data-target="#-sidenav-4" role="button" aria-expanded="false" aria-controls="-sidenav-4"><span>Packages</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-4"><li class="nav-item"><a class="nav-link" href="/tools/pub/packages"><div><span>How to use packages</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/useful-packages"><div><span>Commonly used packages</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/create-packages"><div><span>Creating packages</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/publishing"><div><span>Publishing packages</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/writing-package-pages"><div><span>Writing package pages</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/workspaces"><div><span>Workspaces (monorepo support)</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-4-7" role="button" aria-expanded="false" aria-controls="-sidenav-4-7"><span>Package reference</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-4-7"><li class="nav-item"><a class="nav-link" href="/tools/pub/dependencies"><div><span>Dependencies</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/glossary"><div><span>Glossary</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/package-layout"><div><span>Package layout conventions</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/environment-variables"><div><span>Pub environment variables</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/pubspec"><div><span>Pubspec file</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/troubleshoot"><div><span>Troubleshooting pub</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/verified-publishers"><div><span>Verified publishers</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/security-advisories"><div><span>Security advisories</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/versioning"><div><span>Versioning</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/custom-package-repositories"><div><span>Custom package repositories</span></div></a></li></ul></li><li class="nav-item"><a class="nav-link" href="/tools/pub/private-files"><div><span>What not to commit</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsed collapsible" data-toggle="collapse" data-target="#-sidenav-5" role="button" aria-expanded="false" aria-controls="-sidenav-5"><span>Development</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-5"><li class="nav-item"><a class="nav-link" href="/libraries/serialization/json"><div><span>JSON serialization</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/language/number-representation"><div><span>Number representation</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/google-apis"><div><span>Google APIs</span></div></a></li><li class="nav-item"><a class="nav-link" href="/multiplatform-apps"><div><span>Multi-platform apps</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-5-5" role="button" aria-expanded="false" aria-controls="-sidenav-5-5"><span>Command-line & server apps</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-5-5"><li class="nav-item"><a class="nav-link" href="/server"><div><span>Overview</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/get-started"><div><span>Get started</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/cmdline"><div><span>Write command-line apps</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/fetch-data"><div><span>Fetch data from the internet</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/httpserver"><div><span>Write HTTP servers</span></div></a></li><li class="nav-item"><a class="nav-link" href="/server/libraries"><div><span>Libraries & packages</span></div></a></li><li class="nav-item"><a class="nav-link" href="/server/google-cloud"><div><span>Google Cloud</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-5-6" role="button" aria-expanded="false" aria-controls="-sidenav-5-6"><span>Web apps</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-5-6"><li class="nav-item"><a class="nav-link" href="/web"><div><span>Overview</span></div></a></li><li class="nav-item"><a class="nav-link" href="/web/get-started"><div><span>Get started</span></div></a></li><li class="nav-item"><a class="nav-link" href="/web/deployment"><div><span>Deployment</span></div></a></li><li class="nav-item"><a class="nav-link" href="/web/libraries"><div><span>Libraries & packages</span></div></a></li><li class="nav-item"><a class="nav-link" href="/web/wasm"><div><span>Wasm compilation</span></div></a></li></ul></li><li class="nav-item"><a class="nav-link" href="/libraries/core/environment-declarations"><div><span>Environment declarations</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsed collapsible" data-toggle="collapse" data-target="#-sidenav-6" role="button" aria-expanded="false" aria-controls="-sidenav-6"><span>Interoperability</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-6"><li class="nav-item"><a class="nav-link" href="/interop/c-interop"><div><span>C interop</span></div></a></li><li class="nav-item"><a class="nav-link" href="/interop/objective-c-interop"><div><span>Objective-C & Swift interop</span></div></a></li><li class="nav-item"><a class="nav-link" href="/interop/java-interop"><div><span>Java & Kotlin interop</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-6-4" role="button" aria-expanded="false" aria-controls="-sidenav-6-4"><span>JavaScript interop</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-6-4"><li class="nav-item"><a class="nav-link" href="/interop/js-interop"><div><span>Overview</span></div></a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/usage"><div><span>Usage</span></div></a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/js-types"><div><span>JS types</span></div></a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/tutorials"><div><span>Tutorials</span></div></a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/past-js-interop"><div><span>Past JS interop</span></div></a></li><div class="sidenav-divider"></div><li class="nav-item"><a class="nav-link" href="/interop/js-interop/package-web"><div><span>Web interop</span></div></a></li></ul></li></ul></li><li class="nav-item"><button class="nav-link active collapsible" data-toggle="collapse" data-target="#-sidenav-7" role="button" aria-expanded="true" aria-controls="-sidenav-7"><span>Tools & techniques</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse show" id="-sidenav-7"><li class="nav-item"><a class="nav-link" href="/tools"><div><span>Overview</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-7-2" role="button" aria-expanded="false" aria-controls="-sidenav-7-2"><span>Editors & debuggers</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-7-2"><li class="nav-item"><a class="nav-link" href="/tools/jetbrains-plugin"><div><span>IntelliJ & Android Studio</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/vs-code"><div><span>VS Code</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-devtools"><div><span>Dart DevTools</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-7-2-4" role="button" aria-expanded="false" aria-controls="-sidenav-7-2-4"><span>DartPad</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-7-2-4"><li class="nav-item"><a class="nav-link" href="/tools/dartpad"><div><span>Overview</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dartpad/troubleshoot"><div><span>Troubleshooting DartPad</span></div></a></li></ul></li></ul></li><li class="nav-item"><button class="nav-link active collapsible" data-toggle="collapse" data-target="#-sidenav-7-3" role="button" aria-expanded="true" aria-controls="-sidenav-7-3"><span>Command-line tools</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse show" id="-sidenav-7-3"><li class="nav-item"><button class="nav-link active collapsible" data-toggle="collapse" data-target="#-sidenav-7-3-1" role="button" aria-expanded="true" aria-controls="-sidenav-7-3-1"><span>Dart SDK</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse show" id="-sidenav-7-3-1"><li class="nav-item"><a class="nav-link" href="/tools/sdk"><div><span>Overview</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-tool"><div><span>dart</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-analyze"><div><span>dart analyze</span></div></a></li><li class="nav-item"><a class="nav-link active" href="/tools/dart-compile"><div><span>dart compile</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-create"><div><span>dart create</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-doc"><div><span>dart doc</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-fix"><div><span>dart fix</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-format"><div><span>dart format</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-info"><div><span>dart info</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/cmd"><div><span>dart pub</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-run"><div><span>dart run</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-test"><div><span>dart test</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/dartaotruntime"><div><span>dartaotruntime</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/experiment-flags"><div><span>Experiment flags</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible" data-toggle="collapse" data-target="#-sidenav-7-3-2" role="button" aria-expanded="true" aria-controls="-sidenav-7-3-2"><span>Other command-line tools</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse show" id="-sidenav-7-3-2"><li class="nav-item"><a class="nav-link" href="/tools/build_runner"><div><span>build_runner</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/webdev"><div><span>webdev</span></div></a></li></ul></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-7-4" role="button" aria-expanded="false" aria-controls="-sidenav-7-4"><span>Static analysis</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-7-4"><li class="nav-item"><a class="nav-link" href="/tools/analysis"><div><span>Customizing static analysis</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/non-promotion-reasons"><div><span>Fixing type promotion failures</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/linter-rules"><div><span>Linter rules</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tools/diagnostic-messages"><div><span>Diagnostic messages</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-7-5" role="button" aria-expanded="false" aria-controls="-sidenav-7-5"><span>Testing & optimization</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-7-5"><li class="nav-item"><a class="nav-link" href="/tools/testing"><div><span>Testing</span></div></a></li><li class="nav-item"><a class="nav-link" href="/web/debugging"><div><span>Debugging web apps</span></div></a></li></ul></li></ul></li><li aria-hidden="true"><div class="sidenav-divider"></div></li><li class="nav-item"><button class="nav-link collapsed collapsible" data-toggle="collapse" data-target="#-sidenav-9" role="button" aria-expanded="false" aria-controls="-sidenav-9"><span>Resources</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-9"><li class="nav-item"><a class="nav-link" href="/resources/dart-cheatsheet"><div><span>Language cheatsheet</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/breaking-changes"><div><span>Breaking changes</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/language/evolution"><div><span>Language evolution</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/language/spec"><div><span>Language specification</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/dart-3-migration"><div><span>Dart 3 migration guide</span></div></a></li><li class="nav-item"><button class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#-sidenav-9-6" role="button" aria-expanded="false" aria-controls="-sidenav-9-6"><span>Coming from ...</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse" id="-sidenav-9-6"><li class="nav-item"><a class="nav-link" href="/resources/coming-from/js-to-dart"><div><span>JavaScript to Dart</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/coming-from/swift-to-dart"><div><span>Swift to Dart</span></div></a></li></ul></li><div class="sidenav-divider"></div><li class="nav-item"><a class="nav-link" href="/resources/faq"><div><span>FAQ</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/glossary"><div><span>Glossary</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/books"><div><span>Books</span></div></a></li><li class="nav-item"><a class="nav-link" href="/resources/videos"><div><span>Videos</span></div></a></li><li class="nav-item"><a class="nav-link" href="/tutorials"><div><span>Tutorials</span></div></a></li></ul></li><li class="nav-item"><button class="nav-link collapsible" data-toggle="collapse" data-target="#-sidenav-10" role="button" aria-expanded="true" aria-controls="-sidenav-10"><span>Related sites</span> <span class="material-symbols expander" aria-hidden="true">expand_more</span></button><ul class="nav collapse show" id="-sidenav-10"><li class="nav-item"><a class="nav-link" href="https://api.dart.dev" target="_blank" rel="noopener"><div><span>API reference</span><span class="material-symbols" aria-hidden="true">open_in_new</span></div></a></li><li class="nav-item"><a class="nav-link" href="https://medium.com/dartlang" target="_blank" rel="noopener"><div><span>Blog</span><span class="material-symbols" aria-hidden="true">open_in_new</span></div></a></li><li class="nav-item"><a class="nav-link" href="https://dartpad.dev" target="_blank" rel="noopener"><div><span>DartPad (online editor)</span><span class="material-symbols" aria-hidden="true">open_in_new</span></div></a></li><li class="nav-item"><a class="nav-link" href="https://flutter.dev" target="_blank" rel="noopener"><div><span>Flutter</span><span class="material-symbols" aria-hidden="true">open_in_new</span></div></a></li><li class="nav-item"><a class="nav-link" href="https://pub.dev" target="_blank" rel="noopener"><div><span>Package site</span><span class="material-symbols" aria-hidden="true">open_in_new</span></div></a></li></ul></li></ul></div><main id="page-content"><div id="site-toc--side" class="site-toc"><header class="site-toc__title">Contents</header><ul class="section-nav"><li class="toc-entry nav-item"><a class="nav-link" href="#subcommands">Subcommands</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#types-of-output">Types of output</a><ul class="nav"><li class="toc-entry nav-item"><a class="nav-link" href="#exe">Self-contained executables (exe)</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#aot-snapshot">AOT modules (aot-snapshot)</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#jit-snapshot">JIT modules (jit-snapshot)</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#kernel">Portable modules (kernel)</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#js">JavaScript (js)</a></li></ul></li></ul></div><article><div class="content"><div id="site-content-title"><h1>dart compile</h1></div><div id="site-toc--inline" class="site-toc"><header class="site-toc__title">Contents</header><ul class="section-nav"><li class="toc-entry"><a href="#subcommands">Subcommands</a></li><li class="toc-entry"><a href="#types-of-output">Types of output</a><ul><li class="toc-entry"><a href="#exe">Self-contained executables (exe)</a></li><li class="toc-entry"><a href="#aot-snapshot">AOT modules (aot-snapshot)</a></li><li class="toc-entry"><a href="#jit-snapshot">JIT modules (jit-snapshot)</a></li><li class="toc-entry"><a href="#kernel">Portable modules (kernel)</a></li><li class="toc-entry"><a href="#js">JavaScript (js)</a></li></ul></li></ul></div><p>Use the <code>dart compile</code> command to compile a Dart program to a <a href="/overview#platform">target platform</a>. The output鈥攚hich you specify using a subcommand鈥攃an either include a <a href="/overview#runtime">Dart runtime</a> or be a <em>module</em> (also known as a <em>snapshot</em>).</p><aside class="alert alert-success"><div class="alert-header"><span class="material-symbols" aria-hidden="true">lightbulb</span> <span>Tip</span></div><div class="alert-content"><p>To learn more information about this and other <code>dart</code> commands, check out the <a href="/tools/dart-tool">Dart command-line tool page</a>.</p></div></aside><p>Here's an example of using the <code>exe</code> subcommand to produce a self-contained executable file (<code>myapp.exe</code>):</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile exe bin/myapp.dart</span></span> <span class="line"><span style="color:#222222">Generated: /Users/me/myapp/bin/myapp.exe</span></span></code></pre></div></div><p>The next example uses the <code>aot-snapshot</code> subcommand to produce an ahead-of-time (AOT) compiled module (<code>myapp.aot</code>). It then uses the <a href="/tools/dartaotruntime"><code>dartaotruntime</code> command</a> (which provides a <a href="/overview#runtime">Dart runtime</a>) to run the AOT module:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile aot-snapshot bin/myapp.dart</span></span> <span class="line"><span style="color:#222222">Generated: /Users/me/myapp/bin/myapp.aot</span></span> <span class="line"><span style="color:#222222">$ dartaotruntime bin/myapp.aot</span></span></code></pre></div></div><p>To specify the path to the output file, use the <code>-o</code> or <code>--output</code> option:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile exe bin/myapp.dart -o bin/runme</span></span></code></pre></div></div><p>For more options and usage information, run <code>dart compile [&lt;subcommand&gt;] --help</code>:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile exe --help</span></span></code></pre></div></div><p>The <code>dart compile</code> command replaces the <code>dart2native</code>, <code>dart2aot</code>, and <code>dart2js</code> commands.</p><aside class="alert alert-info"><div class="alert-header"><span class="material-symbols" aria-hidden="true">info</span> <span>Note</span></div><div class="alert-content"><p>You don't need to compile Dart programs before running them. Instead, you can use the <a href="/tools/dart-run"><code>dart run</code> command</a>, which uses the Dart VM's JIT (just-in-time) compiler鈥攁 feature that's especially useful during development. For more information on AOT and JIT compilation, see the <a href="/overview#platform">platforms discussion</a>.</p></div></aside><p>Refer to the <a href="https://github.com/dart-lang/samples/tree/main/native_app">native_app</a> sample for a simple example of using <code>dart compile</code> to compile a native app, followed by examples of running the app.</p><div class="header-wrapper"><h2 id="subcommands">Subcommands</h2><a class="heading-link" href="#subcommands" aria-label="Link to 'Subcommands' section">#</a></div><p>The following table shows the subcommands of <code>dart compile</code>.</p><table class="table table-striped nowrap"><tr><th>Subcommand</th><th>Output</th><th>More information</th></tr><tr><td><code>exe</code></td><td><span style="white-space: nowrap">Self-contained</span> executable</td><td>A standalone, architecture-specific executable file containing the source code compiled to machine code and a small <a href="/overview#runtime">Dart runtime</a>.<br><em><a href="#exe">Learn more.</a></em></td></tr><tr><td style="white-space: nowrap"><code>aot-snapshot</code></td><td style="white-space: nowrap">AOT module</td><td>An architecture-specific file containing the source code compiled to machine code, but <b>no Dart runtime</b>.<br><em><a href="#aot-snapshot">Learn more.</a></em></td></tr><tr><td><code>jit-snapshot</code></td><td>JIT module</td><td>An architecture-specific file with an intermediate representation of all source code, plus an optimized representation of the source code that executed during a training run of the program. JIT-compiled code can have faster peak performance than AOT code if the training data is good.<br><em><a href="#jit-snapshot">Learn more.</a></em></td></tr><tr><td><code>kernel</code></td><td>Kernel module</td><td>A portable, <a href="https://github.com/dart-lang/sdk/blob/main/pkg/kernel/binary.md">intermediate representation</a> of the source code.<br><em><a href="#kernel">Learn more.</a></em></td></tr><tr><td><code>js</code></td><td>JavaScript</td><td>A deployable JavaScript file, compiled from the source code.<br><em><a href="#js">Learn more.</a></em></td></tr><tr><td><code>wasm</code></td><td>WebAssembly</td><td>A portable, binary instruction format for a stack-based virtual machine. Currently under development.<br><em><a href="/web/wasm">Learn more.</a></em></td></tr></table><div class="header-wrapper"><h2 id="types-of-output">Types of output</h2><a class="heading-link" href="#types-of-output" aria-label="Link to 'Types of output' section">#</a></div><p>The following sections have details about each type of output that <code>dart compile</code> can produce.</p><div class="header-wrapper"><h3 id="exe">Self-contained executables (exe)</h3><a class="heading-link" href="#exe" aria-label="Link to 'Self-contained executables (exe)' section">#</a></div><p>The <code>exe</code> subcommand produces a standalone executable for Windows, macOS, or Linux. A <strong>standalone executable</strong> is native machine code that's compiled from the specified Dart file and its dependencies, plus a small <a href="/overview#runtime">Dart runtime</a> that handles type checking and garbage collection.</p><p>You can distribute and run the output file like you would any other executable file.</p><p>Compile your app and set the output file:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile exe bin/myapp.dart -o /tmp/myapp</span></span></code></pre></div></div><p>When successful, this command outputs the following:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">Generated: /tmp/myapp</span></span></code></pre></div></div><p>Run your compiled app from the <code>/tmp</code> directory:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ ./tmp/myapp</span></span></code></pre></div></div><div class="header-wrapper"><h4 id="signing">Signing</h4><a class="heading-link" href="#signing" aria-label="Link to 'Signing' section">#</a></div><p>Executables created with <code>dart compile exe</code> support signing on macOS and Windows.</p><p>To learn more about platform-specific code signing, see the platform documentation for those operating systems:</p><ul><li>Windows <a href="https://docs.microsoft.com/dotnet/framework/tools/signtool-exe"><code>SignTool.exe</code> documentation</a></li><li><a href="https://developer.apple.com/support/code-signing/">Apple Code Signing guide</a></li></ul><div class="header-wrapper"><h4 id="known-limitations">Known limitations</h4><a class="heading-link" href="#known-limitations" aria-label="Link to 'Known limitations' section">#</a></div><p>The <code>exe</code> subcommand has some known limitations:</p><dl><dt>No cross-compilation support (<a href="https://github.com/dart-lang/sdk/issues/28617">issue 28617</a>)</dt><dd>The compiler can create machine code only for the operating system on which you're compiling. To create executables for macOS, Windows, and Linux, you need to run the compiler three times. You can also use a continuous integration (CI) provider that supports all three operating systems.</dd><dt>No support for <code>dart:mirrors</code> and <code>dart:developer</code></dt><dd>For a complete list of the core libraries you can use, see the <a href="/libraries#multi-platform-libraries">Multi-platform</a> and <a href="/libraries#native-platform-libraries">Native platform</a> library tables.</dd></dl><aside class="alert alert-success"><div class="alert-header"><span class="material-symbols" aria-hidden="true">lightbulb</span> <span>Tip</span></div><div class="alert-content"><p>If one of these issues is important to you, let the Dart team know by adding a &quot;thumbs up&quot; to the issue.</p></div></aside><div class="header-wrapper"><h3 id="aot-snapshot">AOT modules (aot-snapshot)</h3><a class="heading-link" href="#aot-snapshot" aria-label="Link to 'AOT modules (aot-snapshot)' section">#</a></div><p>Use AOT modules to reduce disk space requirements when distributing multiple command-line apps. The <code>aot-snapshot</code> subcommand produces an output file specific to the current architecture on which you compile your app.</p><p>For example, if you use macOS to create a <code>.aot</code> file, then that file can run on macOS only. Dart supports AOT modules on Windows, macOS, and Linux.</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile aot-snapshot bin/myapp.dart</span></span> <span class="line"><span style="color:#222222">Generated: /Users/me/myapp/bin/myapp.aot</span></span> <span class="line"><span style="color:#222222">$ dartaotruntime bin/myapp.aot</span></span></code></pre></div></div><p>The <code>aot-snapshot</code> subcommand has some known limitations.</p><dl><dt>No cross-compilation support (<a href="https://github.com/dart-lang/sdk/issues/28617">issue 28617</a>)</dt><dd>The compiler can create machine code only for the operating system on which you're compiling. To create executables for macOS, Windows, and Linux, you need to run the compiler three times. You can also use a continuous integration (CI) provider that supports all three operating systems.</dd><dt>No support for <code>dart:mirrors</code> and <code>dart:developer</code></dt><dd>For a complete list of the core libraries you can use, see the <a href="/libraries#multi-platform-libraries">Multi-platform</a> and <a href="/libraries#native-platform-libraries">Native platform</a> library tables.</dd></dl><aside class="alert alert-success"><div class="alert-header"><span class="material-symbols" aria-hidden="true">lightbulb</span> <span>Tip</span></div><div class="alert-content"><p>If one of these issues is important to you, let the Dart team know by adding a &quot;thumbs up&quot; to the issue.</p></div></aside><p>To learn more, see the <a href="/tools/dartaotruntime"><code>dartaotruntime</code> documentation</a>.</p><div class="header-wrapper"><h3 id="jit-snapshot">JIT modules (jit-snapshot)</h3><a class="heading-link" href="#jit-snapshot" aria-label="Link to 'JIT modules (jit-snapshot)' section">#</a></div><p>JIT modules include all the parsed classes and compiled code that's generated during a training run of a program.</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile jit-snapshot bin/myapp.dart</span></span> <span class="line"><span style="color:#222222">Compiling bin/myapp.dart to jit-snapshot file bin/myapp.jit.</span></span> <span class="line"><span style="color:#222222">Hello world!</span></span> <span class="line"><span style="color:#222222">$ dart run bin/myapp.jit</span></span> <span class="line"><span style="color:#222222">Hello world!</span></span></code></pre></div></div><p>When running from an application module, the Dart VM doesn't need to parse or compile classes and functions that were already used during the training run, so the VM starts running user code sooner.</p><p>These modules are architecture specific, unlike modules produced using the <a href="#kernel"><code>kernel</code> subcommand</a>.</p><div class="header-wrapper"><h3 id="kernel">Portable modules (kernel)</h3><a class="heading-link" href="#kernel" aria-label="Link to 'Portable modules (kernel)' section">#</a></div><p>Use the <code>kernel</code> subcommand to package up an app into a single, portable file that can be run on all operating systems and CPU architectures. A kernel module contains a binary form of the abstract syntax tree (<a href="https://github.com/dart-lang/sdk/blob/main/pkg/kernel/README.md">Kernel AST</a>) for a Dart program.</p><p>Here's an example of creating and running a kernel module:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile kernel bin/myapp.dart</span></span> <span class="line"><span style="color:#222222">Compiling bin/myapp.dart to kernel file bin/myapp.dill.</span></span> <span class="line"><span style="color:#222222">$ dart run bin/myapp.dill</span></span></code></pre></div></div><p>Although kernel modules have reduced startup time compared to Dart code, they can have much slower startup than architecture-specific AOT output formats.</p><div class="header-wrapper"><h3 id="js">JavaScript (js)</h3><a class="heading-link" href="#js" aria-label="Link to 'JavaScript (js)' section">#</a></div><p>The <code>js</code> subcommand compiles Dart code to deployable JavaScript.</p><aside class="alert alert-info"><div class="alert-header"><span class="material-symbols" aria-hidden="true">info</span> <span>Note</span></div><div class="alert-content"><p>Use the <a href="/tools/webdev"><code>webdev</code> tool</a> rather than running the Dart-to-JavaScript compiler.</p><ul><li><p>The <a href="/tools/webdev#build"><code>webdev build</code></a> command, by default, produces minified, deployable JavaScript.</p></li><li><p>The <a href="/tools/webdev#serve"><code>webdev serve</code></a> command, by default, produces JavaScript modules for running and debugging during development.</p></li></ul></div></aside><div class="header-wrapper"><h4 id="prod-compile-options">Options</h4><a class="heading-link" href="#prod-compile-options" aria-label="Link to 'Options' section">#</a></div><p>The <code>dart compile js</code> command has multiple options to customize javascript code compilation.</p><ul><li><a href="#basic-options">Basic options</a></li><li><a href="#path-and-environment-options">Path and environment options</a></li><li><a href="#display-options">Display options</a></li><li><a href="#analysis-options">Analysis options</a></li></ul><div class="header-wrapper"><h6 id="basic-options">Basic options</h6><a class="heading-link" href="#basic-options" aria-label="Link to 'Basic options' section">#</a></div><p>Common options include:</p><dl><dt><code>-o &lt;file&gt;</code> or <code>--output=&lt;file&gt;</code></dt><dd><p>Generates the output into <code>&lt;file&gt;</code>. If not specified, the output goes in a file named <code>out.js</code>.</p></dd><dt><code>--enable-asserts</code></dt><dd><p>Enables assertion checking.</p></dd><dt><code>-O{0|1|2|3|4}</code></dt><dd><p>Controls optimizations to reduce file size and improve code performance. To learn more about these optimizations, run <code>dart compile js -hv</code>.</p><ul><li><p><code>-O0</code>: Disables many optimizations.</p></li><li><p><code>-O1</code>: Enables default optimizations.</p></li><li><p><code>-O2</code>: Enables <code>-O1</code> optimizations, plus additional ones (such as minification) that respect the language semantics and are safe for all programs.</p><aside class="alert alert-info"><div class="alert-header"><span class="material-symbols" aria-hidden="true">info</span> <span>Note</span></div><div class="alert-content"><p>With <code>-O2</code>, string representations of types are no longer the same as those in the Dart VM when compiled with the development JavaScript compiler.</p></div></aside></li><li><p><code>-O3</code>: Enables <code>-O2</code> optimizations, plus omits implicit type checks.</p><aside class="alert alert-warning"><div class="alert-header"><span class="material-symbols" aria-hidden="true">warning</span> <span>Warning</span></div><div class="alert-content"><p>Omitting type checks can cause your app to crash due to type errors. Before using <code>-O3</code>, <strong>test using <code>-O2</code></strong> to ensure that your app <strong>never</strong> throws a subtype of <code>Error</code> (such as <code>TypeError</code>).</p></div></aside></li><li><p><code>-O4</code>: Enables more aggressive optimizations than <code>-O3</code>, but with the same assumptions.</p><aside class="alert alert-warning"><div class="alert-header"><span class="material-symbols" aria-hidden="true">warning</span> <span>Warning</span></div><div class="alert-content"><p>The <code>-O4</code> optimizations are susceptible to variations in input data. Before relying on <code>-O4</code>, <strong>test for edge cases in user input</strong>.</p></div></aside></li></ul></dd><dt><code>--no-source-maps</code></dt><dd><p>Do not generate a source map file.</p></dd><dt><code>-h</code> or <code>--help</code></dt><dd><p>Displays help. To get information about all options, use <code>-hv</code>.</p></dd></dl><div class="header-wrapper"><h6 id="path-and-environment-options">Path and environment options</h6><a class="heading-link" href="#path-and-environment-options" aria-label="Link to 'Path and environment options' section">#</a></div><p>Some other handy options include:</p><dl><dt><code>--packages=&lt;path&gt;</code></dt><dd>Specifies the path to the package resolution configuration file. For more information, check out the <a href="https://github.com/dart-lang/language/blob/main/accepted/2.8/language-versioning/package-config-file-v2.md">Dart package configuration file</a> specification.</dd><dt><code>-D&lt;flag&gt;=&lt;value&gt;</code></dt><dd>Defines an environment declaration and value pair which can be accessed with <a href="https://api.dart.dev/dart-core/String/String.fromEnvironment.html"><code>String.fromEnvironment</code></a>, <a href="https://api.dart.dev/dart-core/int/int.fromEnvironment.html"><code>int.fromEnvironment</code></a>, <a href="https://api.dart.dev/dart-core/bool/bool.fromEnvironment.html"><code>bool.fromEnvironment</code></a>, or <a href="https://api.dart.dev/dart-core/bool/bool.hasEnvironment.html"><code>bool.hasEnvironment</code></a>. To learn more about environment declarations, see <a href="/libraries/core/environment-declarations">Configuring apps with compilation environment declarations</a>.</dd><dt><code>--version</code></dt><dd>Displays version information for <code>dart</code>.</dd></dl><div class="header-wrapper"><h6 id="display-options">Display options</h6><a class="heading-link" href="#display-options" aria-label="Link to 'Display options' section">#</a></div><p>The following options help you control the compiler output.</p><dl><dt><code>--suppress-warnings</code></dt><dd>Doesn't display warnings.</dd><dt><code>--suppress-hints</code></dt><dd>Doesn't display hints.</dd><dt><code>--terse</code></dt><dd>Emits diagnostics, without suggesting how to get rid of the diagnosed problems.</dd><dt><code>-v</code> or <code>--verbose</code></dt><dd>Displays lots of information.</dd></dl><div class="header-wrapper"><h6 id="analysis-options">Analysis options</h6><a class="heading-link" href="#analysis-options" aria-label="Link to 'Analysis options' section">#</a></div><p>The following options control the analysis performed on Dart code.</p><dl><dt><code>--fatal-warnings</code></dt><dd>Treat warnings as compilation errors.</dd><dt><code>--enable-diagnostic-colors</code></dt><dd>Adds colors to diagnostic messages.</dd><dt><code>--show-package-warnings</code></dt><dd>Shows warnings and hints generated from packages.</dd><dt><code>--csp</code></dt><dd>Disables dynamic generation of code in the generated output. This is necessary to satisfy CSP restrictions (see <a href="https://www.w3.org/TR/CSP/">W3C Content Security Policy.</a>)</dd><dt><code>--dump-info</code></dt><dd>Generates a file (with the suffix <code>.info.json</code>) that contains information about the generated code. You can inspect the generated file with tools in <a href="/go/dart2js-info">dart2js_info</a>.</dd></dl><div class="header-wrapper"><h4 id="compiling-web-app-example">Compiling web app example</h4><a class="heading-link" href="#compiling-web-app-example" aria-label="Link to 'Compiling web app example' section">#</a></div><p>For example, to compile a Dart application to optimized JavaScript, run the following command:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart compile js -O2 -o out/main.js web/main.dart</span></span></code></pre></div></div><div class="header-wrapper"><h4 id="helping-generate-efficient-code">Improving production web compilation</h4><a class="heading-link" href="#helping-generate-efficient-code" aria-label="Link to 'Improving production web compilation' section">#</a></div><p>Follow these practices to improve type inference, reduce file size, and improve JavaScript performance:</p><ul><li>Don't use <code>Function.apply()</code>.</li><li>Don't override <code>noSuchMethod()</code>.</li><li>Avoid setting variables to <code>null</code>.</li><li>Be consistent with the types of arguments you pass into each function or method.</li></ul><aside class="alert alert-success"><div class="alert-header"><span class="material-symbols" aria-hidden="true">lightbulb</span> <span>Tip</span></div><div class="alert-content"><p>Don't worry about the size of your app's included libraries. The production compiler performs tree shaking to omit unused classes, functions, methods, and so on. Import the libraries you think you'll need, and let the compiler get rid of what it doesn't need.</p></div></aside><p>To learn more about building and deploying JavaScript applications, check out <a href="/web/deployment">Web deployment</a>.</p><p id="page-github-links"><span>Unless stated otherwise, the documentation on this site reflects Dart 3.7.2. Page last updated on 2024-05-13.</span> <a href="https://github.com/dart-lang/site-www/tree/main/src/content/tools/dart-compile.md" target="_blank" rel="noopener">View source</a> <span>or </span><a href="https://github.com/dart-lang/site-www/issues/new?template=1_page_issue.yml&page-url=https://dart.dev/tools/dart-compile/&page-source=https://github.com/dart-lang/site-www/tree/main/src/content/tools/dart-compile.md" title="Report an issue with this page" target="_blank" rel="noopener">report an issue</a>.</p></div></article></main></div><footer id="page-footer"><div class="footer-section footer-main"><a href="/" class="brand" title="Dart"><img src="/assets/img/logo/logo-white-text.svg" alt="Dart" width="164"></a><div class="footer-social-links"><a href="https://medium.com/dartlang" target="_blank" rel="noopener" title="Dart's Medium publication"><svg><use href="/assets/img/social/medium.svg#medium"></use></svg> </a><a href="https://github.com/dart-lang" target="_blank" rel="noopener" title="Dart's GitHub organization"><svg><use href="/assets/img/social/github.svg#github"></use></svg> </a><a href="https://bsky.app/profile/dart.dev" target="_blank" rel="noopener" title="Dart's Bluesky profile"><svg><use href="/assets/img/social/bluesky.svg#bluesky"></use></svg> </a><a href="https://twitter.com/dart_lang" target="_blank" rel="noopener" title="Dart's X (Twitter) profile"><svg><use href="/assets/img/social/x.svg#x"></use></svg></a></div></div><div class="footer-section footer-tray"><div class="footer-licenses">Except as otherwise noted, this site is licensed under a <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>, and code samples are licensed under the <a href="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</a>.</div><div class="footer-utility-links"><ul><li><a href="/terms" title="Terms of use">Terms</a></li><li><a href="https://policies.google.com/privacy" target="_blank" rel="noopener" title="Privacy policy">Privacy</a></li><li><a href="/security" title="Security philosophy and practices">Security</a></li></ul></div></div></footer></div></body></html>

Pages: 1 2 3 4 5 6 7 8 9 10