Dart 3.11 is live!Learn more
webdev
Command-line tools for Dart web development.
This page explains how to usewebdev to compile your app andbuild_runner to test your app.
Setup
#Follow these instructions to get started usingwebdev.
Before you can usewebdev, Add dependencies to thebuild_runner andbuild_web_compilers packages to your app. Thebuild_runner package adds scripting capabilities towebdev.
dart pub add build_runner build_web_compilers --devInstalling and updating webdev
# Usedart pub to installwebdev forall users.
dart pub global activate webdev Use the same command to updatewebdev. Updatewebdev when you update your Dart SDK or whenwebdev commands fail in a way you can't explain.
Depending on build_* packages
# To usewebdev, you must be in the root directory of a package that depends on thebuild_runner andbuild_web_compilers packages. If you're testing the app, it must also depend onbuild_test.
To depend on these packages, add the followingdev_dependencies to your app'spubspec.yaml file:
dev_dependencies:# ···build_runner:^2.10.4build_test:^3.5.4build_web_compilers:^4.4.3 As usual afterpubspec.yaml changes, rundart pub get ordart pub upgrade:
dart pub getUsing commands from Dart packages to compile and test
# This tool can compile in two ways: one that makes debugging easier (serve) and one that makes for small, fast code (build).
The development compiler supports incremental updates and producesAsynchronous Module Definition (AMD) modules.. Withwebdev serve, you can edit your Dart files, refresh in Chrome, and see your edits in short order. This speed comes from compiling updated modules, not all the packages that your app requires.
The first compilation takes the longest as it compiles the entire app. Whileserve command runs, successive builds should compile faster.
The production compiler generates a single, minified JavaScript file.
This section describes how to use the following commands:
- webdev serve
Runs a development server that continuously builds a JavaScript app.
- webdev build
Builds a deployable version of a JavaScript app.
- build_runner test
Runs tests.
You can customize your build using build configuration files. To learn more about build configuration files, see thebuild_web_compilers package.
webdev serve
#To serve a development version of your web app, run the following command.
$ webdev serve [--debug | --release] [ [<directory>[:<port>]] ... ]This command launches a development server that serves your app and watches for source code changes. By default, this command serves the app atlocalhost:8080:
webdev serve The firstwebdev serve compiles slow. After the first compile, it caches assets on disk. This makes later builds compile faster.
The development compiler supportsonly Chrome. To view your app in another browser, use the production compiler. The production compiler supports the latest two versions of Chrome, Edge, Firefox, and Safari.
To enableDart DevTools, add the--debug flag:
webdev serve --debug # enables Dart DevToolsTo use production compiler instead of development compiler, add the--release flag:
webdev serve --release # uses production compilerYou can specify different directory-port configurations.
For example, the following command changes the test port from the default (8081) to 8083:
webdev serve web test:8083 # App: 8080; tests: 8083webdev build
#Use the following command to build your app:
$ webdev build [--no-release] --output [<dirname>:]<dirname> By default, thebuild command uses the production JavaScript compiler to create a production version of your app. Add--no-release to compile with the development JavaScript compiler. Use the--output option to control where Dart compiles top-level project folders and writes its output.
The following command shows how to compile the project's top-levelweb folder into thebuild directory. This command uses the production JavaScript compiler by default.
webdev build --output web:buildbuild_runner test
#Use thebuild_runner test command to run your app's component tests:
dart run build_runner test [build_runner options] -- -p <platform> [test options] If the command fails to load the test file, make sure that your app'spubspec has adev_dependency onbuild_test.
For example, here's how to run all Chrome platform tests:
dart run build_runner test -- -p chromeTo see all available build_runner options, use the--help or-h option:
dart run build_runner test -h Dart passes arguments after the empty-- argument directly to thetest package runner. To see all command-line options for the test package runner, use this command:
dart test -hMore information
# For a complete list ofwebdev options, runwebdev --help or see thewebdev package.
Also see the following pages:
- build_runner: Introduces build_runner and its built-in commands, and points to more information.
- build_web_compilers: Has information on configuring builds, with an example of using
dart2js_argsto specifycompiler options.
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Page last updated on 2025-11-24.View source orreport an issue.