Web deployment

    Use the webdev tool to build your app,compiling it to JavaScript and generating all the assetsyou need for deployment.When you build using ,you get a JavaScript file that’s reasonably small,thanks to the dart2js compiler’s support for tree shaking.

    With a little extra work, you can make your deployable appsmaller, faster, and more reliable.

    to createa deployable version of your app.Here’s what happens when you use webdev with dart2jsand the option:

    • Deployable files appear under your app’s build/web directory.
    • dart2js compiles your app to JavaScript, saving the resultin the file build/web/main.dart.js.

    For more information, see the documentation for webdev.

    Google’s apps often use the following :

    • —minify
    • —trust-primitives

    Test your apps before deploying with these options!

    • Build your app both with and without —fast-startup,so you can judge whether the speedup is worth the increase in JavaScript size.
    • The —trust-primitives option can have unexpected results(even in well-typed code) if your data isn’t always valid.

    Important: Make sure your app has good test coverage before you use either of the options. If some code paths aren’t tested, your app might run in dartdevc but misbehave when compiled using dart2js.

    You can specify dart2js options in a build config file,as described in the build_web_compilers README.

    The following steps are optional,but they can help make your app more reliable and responsive.

    Use the pwa package to make your app work offline

    The pwa package simplifies the task ofmaking your app work with limited or no connectivity.For information on using this package, see

    Use deferred loading to reduce your app’s initial size

    You can use Dart’s support for deferred loading toreduce your app’s initial download size.For details, see the language tour’s coverage ofdeferred loadingand the dart-lang/angular page

    Follow best practices for web apps

    The usual advice for web apps applies to Dart web apps.Here are a few resources:

    Remove unneeded build files

    To remove these files, you can run a command like the following:

    Serving your app

    You can serve your Dart Web app just like you’d serve any other web app.This section points to tips for serving Dart Web apps,as well as Dart-specific resources to help you use GitHub Pages or Firebaseto serve your app.

    If your app doesn’t use routing or require server-side support,you can serve the app using GitHub Pages.The package isan easy way to automatically produce a gh-pages branch for any Dart web app.

    The startup_namer exampleis hosted using GitHub Pages.Its files are in the gh-pages branch of theand were built using peanut.

    For a walk-through of using Firebase to serve a chat app, see

    Other resources:

    • The Google I/O 2017 codelabBuild an AngularDart & Firebase Web Appwalks through using Firebase for server-side communication,but doesn’t include instructions for serving the app.
    • The describes how to deploy web apps with Firebase.
    • In the Firebase Hosting documentation,Customize Hosting Behaviorcovers redirects, rewrites, and more.