On this page

pub build

Send feedback

Build is one of the commands of the pub tool. Learn more about pub.

$ pub build [<options>] [<directories>] [--output=<directory>]

Use pub build when you’re ready to deploy your web app. When you run pub build, it generates the assets for the current package and all of its dependencies, putting them into new directory named build.

To use pub build, just run it in your package’s root directory. For example:

$ cd ~/dart/helloworld
$ pub build
Building helloworld......
Built 5 files!

If the build directory already exists, pub build deletes it and then creates it again.

To generate assets, pub build uses transformers. Any source assets that aren’t transformed are copied, as is, into the build directory or one of its subdirectories. Pub also automatically compiles your Dart application to JavaScript using dart2js (or the specified compiler). See Configuring the Built-in dart2js Transformer for information on how to configure the dart2js options in your pubspec.

See Pub Assets and Transformers for information on:

  • Where in your package to put assets.
  • What URLs to use when referring to assets.
  • How to use pubspec.yaml to specify which transformers run, and in what order.

Also see pub serve. With pub serve, you can run a development server that continuously generates and serves assets.


For options that apply to all pub commands, see Global options.

Optional. Use this option to specify directories to use as input for the build command, in addition to lib (which is always processed). The default value is web. Directories you might typically specify include the following:
  • benchmark
  • bin
  • example
  • test
  • web
For example, you might specify:
pub build test benchmark example/foo bar
In the preceding example, the test, benchmark, example/foo, and bar directories are processed, as is the lib directory. The web directory is not built because it isn't specified.
Optional. Builds all of the buildable directories (benchmark, bin, example, test, and web) that are present.
Optional. Specifies a transformation mode. Typical values are "debug" and "release", but any word is allowed. Transformers may use this to change how they behave.

If the mode is "release", then pub generates minified JavaScript using dart2js (or the specified compiler). Otherwise, pub uses dart2js (or the specified compiler) to generate unminified JavaScript. In release mode, pub does not include any source .dart files in the build output. In any other mode, the raw Dart files are included.

If this option is omitted, its default value is "release".
--output=<directory> or -o <directory>
Optional. Specifies where to put the build output. The default is the top-level build directory.
Optional (added in 1.24). Specifies which Dart-to-JavaScript compiler to use. Possible values are "dart2js", "dartdevc", and "none" (no generated JavaScript).

If this option is omitted, its default value is "dart2js".