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,0" rel="stylesheet"><link rel="stylesheet" href="/assets/css/main.css"><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/4.6.2/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.5/js.cookie.min.js" integrity="sha512-nlp9/l96/EpjYBx7EP7pGASVXNe80hGhYAUrjeXnu/fyF5Py0/RXav4BBNs7n5Hx1WFhOEOWSAVjGeC3oKxDVQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="/assets/js/os-tabs.js"></script><script src="/assets/js/utilities.js"></script><script src="/assets/js/main.js"></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 show_banner"><a id="skip" href="#site-content-title">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. <a href="https://policies.google.com/technologies/cookies" target="_blank" rel="noopener">Learn more</a>.</p><button id="cookie-consent" class="btn btn-primary">OK, got it</button></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><header id="page-header" class="site-header"><nav id="mainnav" class="site-header"><div id="menu-toggle"><i class="material-symbols">menu</i></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="/guides" 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 class="banner"><p class="banner__text">Announcing Dart 3.5 and an updated Dart roadmap! <a href="https://medium.com/dartlang/dart-3-5-6ca36259fa2f" target="_blank">Learn more</a></p></div><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><div class="site-sidebar"><ul class="navbar-nav"><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="/guides" class="nav-link">Docs</a></li><li aria-hidden="true"><div class="sidebar-primary-divider"></div></li></ul><ul class="nav flex-column"><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-1" role="button" aria-expanded="false" aria-controls="sidenav-1">Language</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1"><li class="nav-item"><a class="nav-link" href="/language">Introduction</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-2" href="#sidenav-1-2" role="button" aria-expanded="false" aria-controls="sidenav-1-2">Syntax basics</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-2"><li class="nav-item"><a class="nav-link" href="/language/variables">Variables</a></li><li class="nav-item"><a class="nav-link" href="/language/operators">Operators</a></li><li class="nav-item"><a class="nav-link" href="/language/comments">Comments</a></li><li class="nav-item"><a class="nav-link" href="/language/metadata">Metadata</a></li><li class="nav-item"><a class="nav-link" href="/language/libraries">Libraries & imports</a></li><li class="nav-item"><a class="nav-link" href="/language/keywords">Keywords</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-3" href="#sidenav-1-3" role="button" aria-expanded="false" aria-controls="sidenav-1-3">Types</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-3"><li class="nav-item"><a class="nav-link" href="/language/built-in-types">Built-in types</a></li><li class="nav-item"><a class="nav-link" href="/language/records">Records</a></li><li class="nav-item"><a class="nav-link" href="/language/collections">Collections</a></li><li class="nav-item"><a class="nav-link" href="/language/generics">Generics</a></li><li class="nav-item"><a class="nav-link" href="/language/typedefs">Typedefs</a></li><li class="nav-item"><a class="nav-link" href="/language/type-system">Type system</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-4" href="#sidenav-1-4" role="button" aria-expanded="false" aria-controls="sidenav-1-4">Patterns</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-4"><li class="nav-item"><a class="nav-link" href="/language/patterns">Overview & usage</a></li><li class="nav-item"><a class="nav-link" href="/language/pattern-types">Pattern types</a></li><li class="nav-item"><a class="nav-link" href="https://codelabs.developers.google.com/codelabs/dart-patterns-records" target="_blank" rel="noopener">Applied tutorial</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/language/functions">Functions</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-6" href="#sidenav-1-6" role="button" aria-expanded="false" aria-controls="sidenav-1-6">Control flow</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-6"><li class="nav-item"><a class="nav-link" href="/language/loops">Loops</a></li><li class="nav-item"><a class="nav-link" href="/language/branches">Branches</a></li><li class="nav-item"><a class="nav-link" href="/language/error-handling">Error handling</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-7" href="#sidenav-1-7" role="button" aria-expanded="false" aria-controls="sidenav-1-7">Classes & objects</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-7"><li class="nav-item"><a class="nav-link" href="/language/classes">Classes</a></li><li class="nav-item"><a class="nav-link" href="/language/constructors">Constructors</a></li><li class="nav-item"><a class="nav-link" href="/language/methods">Methods</a></li><li class="nav-item"><a class="nav-link" href="/language/extend">Extend a class</a></li><li class="nav-item"><a class="nav-link" href="/language/mixins">Mixins</a></li><li class="nav-item"><a class="nav-link" href="/language/enums">Enums</a></li><li class="nav-item"><a class="nav-link" href="/language/extension-methods">Extension methods</a></li><li class="nav-item"><a class="nav-link" href="/language/extension-types">Extension types</a></li><li class="nav-item"><a class="nav-link" href="/language/callable-objects">Callable objects</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-8" href="#sidenav-1-8" role="button" aria-expanded="false" aria-controls="sidenav-1-8">Class modifiers</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-8"><li class="nav-item"><a class="nav-link" href="/language/class-modifiers">Overview & usage</a></li><li class="nav-item"><a class="nav-link" href="/language/class-modifiers-for-apis">Class modifiers for API maintainers</a></li><li class="nav-item"><a class="nav-link" href="/language/modifier-reference">Reference</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-9" href="#sidenav-1-9" role="button" aria-expanded="false" aria-controls="sidenav-1-9">Concurrency</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-9"><li class="nav-item"><a class="nav-link" href="/language/concurrency">Overview</a></li><li class="nav-item"><a class="nav-link" href="/language/async">Asynchronous support</a></li><li class="nav-item"><a class="nav-link" href="/language/isolates">Isolates</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-10" href="#sidenav-1-10" role="button" aria-expanded="false" aria-controls="sidenav-1-10">Null safety</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-10"><li class="nav-item"><a class="nav-link" href="/null-safety">Sound null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/migration-guide">Migrating to null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/understanding-null-safety">Understanding null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/unsound-null-safety">Unsound null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/faq">FAQ</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-2" role="button" aria-expanded="false" aria-controls="sidenav-2">Core libraries</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-2"><li class="nav-item"><a class="nav-link" href="/libraries">Overview</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-core">dart:core</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-async">dart:async</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-math">dart:math</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-convert">dart:convert</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-io">dart:io</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-html">dart:html</a></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/libraries/collections/iterables">Iterable collections</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-2-10" href="#sidenav-2-10" role="button" aria-expanded="false" aria-controls="sidenav-2-10">Asynchronous programming</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-2-10"><li class="nav-item"><a class="nav-link" href="/libraries/async/async-await">Tutorial</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/futures-error-handling">Futures and error handling</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/using-streams">Using streams</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/creating-streams">Creating streams</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-3" role="button" aria-expanded="false" aria-controls="sidenav-3">Effective Dart</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-3"><li class="nav-item"><a class="nav-link" href="/effective-dart">Overview</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/style">Style</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/documentation">Documentation</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/usage">Usage</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/design">Design</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-4" role="button" aria-expanded="false" aria-controls="sidenav-4">Packages</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-4"><li class="nav-item"><a class="nav-link" href="/tools/pub/packages">How to use packages</a></li><li class="nav-item"><a class="nav-link" href="/resources/useful-packages">Commonly used packages</a></li><li class="nav-item"><a class="nav-link" href="/guides/libraries/create-packages">Creating packages</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/publishing">Publishing packages</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/writing-package-pages">Writing package pages</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-4-6" href="#sidenav-4-6" role="button" aria-expanded="false" aria-controls="sidenav-4-6">Package reference</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-4-6"><li class="nav-item"><a class="nav-link" href="/tools/pub/dependencies">Dependencies</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/glossary">Glossary</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/package-layout">Package layout conventions</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/environment-variables">Pub environment variables</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/pubspec">Pubspec file</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/troubleshoot">Troubleshooting pub</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/verified-publishers">Verified publishers</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/security-advisories">Security advisories</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/versioning">Versioning</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/custom-package-repositories">Custom package repositories</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/guides/libraries/private-files">What not to commit</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-5" role="button" aria-expanded="false" aria-controls="sidenav-5">Development</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5"><li class="nav-item"><a class="nav-link" href="/guides/json">JSON</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/numbers">Number representation</a></li><li class="nav-item"><a class="nav-link" href="/resources/google-apis">Google APIs</a></li><li class="nav-item"><a class="nav-link" href="/multiplatform-apps">Multi-platform apps</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-5-5" href="#sidenav-5-5" role="button" aria-expanded="false" aria-controls="sidenav-5-5">Command-line & server apps</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5-5"><li class="nav-item"><a class="nav-link" href="/server">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/get-started">Get started</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/cmdline">Write command-line apps</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/fetch-data">Fetch data from the internet</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/httpserver">Write HTTP servers</a></li><li class="nav-item"><a class="nav-link" href="/server/libraries">Libraries & packages</a></li><li class="nav-item"><a class="nav-link" href="/server/google-cloud">Google Cloud</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-5-6" href="#sidenav-5-6" role="button" aria-expanded="false" aria-controls="sidenav-5-6">Web apps</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5-6"><li class="nav-item"><a class="nav-link" href="/web">Overview</a></li><li class="nav-item"><a class="nav-link" href="/web/get-started">Get started</a></li><li class="nav-item"><a class="nav-link" href="/web/deployment">Deployment</a></li><li class="nav-item"><a class="nav-link" href="/web/libraries">Libraries & packages</a></li><li class="nav-item"><a class="nav-link" href="/web/wasm">Wasm compilation</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/guides/environment-declarations">Environment declarations</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-6" role="button" aria-expanded="false" aria-controls="sidenav-6">Interoperability</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-6"><li class="nav-item"><a class="nav-link" href="/interop/c-interop">C interop</a></li><li class="nav-item"><a class="nav-link" href="/interop/objective-c-interop">Objective-C & Swift interop</a></li><li class="nav-item"><a class="nav-link" href="/interop/java-interop">Java & Kotlin interop</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-6-4" href="#sidenav-6-4" role="button" aria-expanded="false" aria-controls="sidenav-6-4">JavaScript interop</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-6-4"><li class="nav-item"><a class="nav-link" href="/interop/js-interop">Overview</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/usage">Usage</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/js-types">JS types</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/tutorials">Tutorials</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/past-js-interop">Past JS interop</a></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/interop/js-interop/package-web">Web interop</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link active collapsible" data-toggle="collapse" href="#sidenav-7" role="button" aria-expanded="true" aria-controls="sidenav-7">Tools & techniques</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7"><li class="nav-item"><a class="nav-link" href="/tools">Overview</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-2" href="#sidenav-7-2" role="button" aria-expanded="false" aria-controls="sidenav-7-2">Editors & debuggers</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-2"><li class="nav-item"><a class="nav-link" href="/tools/jetbrains-plugin">IntelliJ & Android Studio</a></li><li class="nav-item"><a class="nav-link" href="/tools/vs-code">VS Code</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-devtools">Dart DevTools</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-2-4" href="#sidenav-7-2-4" role="button" aria-expanded="false" aria-controls="sidenav-7-2-4">DartPad</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-2-4"><li class="nav-item"><a class="nav-link" href="/tools/dartpad">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tools/dartpad/troubleshoot">Troubleshooting DartPad</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link active collapsible" data-toggle="collapse" data-target="#sidenav-7-3" href="#sidenav-7-3" role="button" aria-expanded="true" aria-controls="sidenav-7-3">Command-line tools</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3"><li class="nav-item"><a class="nav-link active collapsible" data-toggle="collapse" data-target="#sidenav-7-3-1" href="#sidenav-7-3-1" role="button" aria-expanded="true" aria-controls="sidenav-7-3-1">Dart SDK</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3-1"><li class="nav-item"><a class="nav-link" href="/tools/sdk">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-tool">dart</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-analyze">dart analyze</a></li><li class="nav-item"><a class="nav-link active" href="/tools/dart-compile">dart compile</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-create">dart create</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-doc">dart doc</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-fix">dart fix</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-format">dart format</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-info">dart info</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/cmd">dart pub</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-run">dart run</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-test">dart test</a></li><li class="nav-item"><a class="nav-link" href="/tools/dartaotruntime">dartaotruntime</a></li><li class="nav-item"><a class="nav-link" href="/tools/experiment-flags">Experiment flags</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" data-target="#sidenav-7-3-2" href="#sidenav-7-3-2" role="button" aria-expanded="true" aria-controls="sidenav-7-3-2">Other command-line tools</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3-2"><li class="nav-item"><a class="nav-link" href="/tools/build_runner">build_runner</a></li><li class="nav-item"><a class="nav-link" href="/tools/webdev">webdev</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-4" href="#sidenav-7-4" role="button" aria-expanded="false" aria-controls="sidenav-7-4">Static analysis</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-4"><li class="nav-item"><a class="nav-link" href="/tools/analysis">Customizing static analysis</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/sound-problems">Fixing common type problems</a></li><li class="nav-item"><a class="nav-link" href="/tools/non-promotion-reasons">Fixing type promotion failures</a></li><li class="nav-item"><a class="nav-link" href="/tools/linter-rules">Linter rules</a></li><li class="nav-item"><a class="nav-link" href="/tools/diagnostic-messages">Diagnostic messages</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-5" href="#sidenav-7-5" role="button" aria-expanded="false" aria-controls="sidenav-7-5">Testing & optimization</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-5"><li class="nav-item"><a class="nav-link" href="/guides/testing">Testing</a></li><li class="nav-item"><a class="nav-link" href="/web/debugging">Debugging web apps</a></li></ul></li></ul></li><li aria-hidden="true"><div class="sidebar-primary-divider"></div></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-9" role="button" aria-expanded="false" aria-controls="sidenav-9">Resources</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-9"><li class="nav-item"><a class="nav-link" href="/resources/dart-cheatsheet">Language cheatsheet</a></li><li class="nav-item"><a class="nav-link" href="/resources/breaking-changes">Breaking changes</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/evolution">Language evolution</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/spec">Language specification</a></li><li class="nav-item"><a class="nav-link" href="/resources/dart-3-migration">Dart 3 migration guide</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-9-6" href="#sidenav-9-6" role="button" aria-expanded="false" aria-controls="sidenav-9-6">Coming from ...</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-9-6"><li class="nav-item"><a class="nav-link" href="/resources/coming-from/js-to-dart">JavaScript to Dart</a></li><li class="nav-item"><a class="nav-link" href="/resources/coming-from/swift-to-dart">Swift to Dart</a></li></ul></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/resources/faq">FAQ</a></li><li class="nav-item"><a class="nav-link" href="/resources/glossary">Glossary</a></li><li class="nav-item"><a class="nav-link" href="/resources/books">Books</a></li><li class="nav-item"><a class="nav-link" href="/resources/videos">Videos</a></li><li class="nav-item"><a class="nav-link" href="/tutorials">Tutorials</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" href="#sidenav-10" role="button" aria-expanded="true" aria-controls="sidenav-10">Related sites</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-10"><li class="nav-item"><a class="nav-link" href="https://api.dart.dev" target="_blank" rel="noopener">API reference</a></li><li class="nav-item"><a class="nav-link" href="https://medium.com/dartlang" target="_blank" rel="noopener">Blog</a></li><li class="nav-item"><a class="nav-link" href="https://dartpad.dev" target="_blank" rel="noopener">DartPad (online editor)</a></li><li class="nav-item"><a class="nav-link" href="https://flutter.dev" target="_blank" rel="noopener">Flutter</a></li><li class="nav-item"><a class="nav-link" href="https://pub.dev" target="_blank" rel="noopener">Package site</a></li></ul></li></ul></div></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"><i class="material-symbols" aria-hidden="true">lightbulb</i> <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"><i class="material-symbols" aria-hidden="true">info</i> <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"><i class="material-symbols" aria-hidden="true">lightbulb</i> <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"><i class="material-symbols" aria-hidden="true">lightbulb</i> <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"><i class="material-symbols" aria-hidden="true">info</i> <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"><i class="material-symbols" aria-hidden="true">info</i> <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"><i class="material-symbols" aria-hidden="true">warning</i> <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"><i class="material-symbols" aria-hidden="true">warning</i> <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="/guides/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"><i class="material-symbols" aria-hidden="true">lightbulb</i> <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.5.4. 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><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="Medium blog"><svg><use href="/assets/img/social/medium.svg#medium"></use></svg> </a><a href="https://github.com/dart-lang" target="_blank" rel="noopener" title="GitHub"><svg><use href="/assets/img/social/github.svg#github"></use></svg> </a><a href="https://twitter.com/dart_lang" target="_blank" rel="noopener" title="X (Twitter)"><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></body></html>

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