pub serve

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

$ pub serve [--hostname=<host>] [--port=<number>] [--mode=<mode>] [<directories>]
$ pub serve [--hostname=<host>] [--port=<number>] [--mode=<mode>] [--all]

This command starts up a development server, or dev server, for your Dart web app. The dev server is an HTTP server on localhost that serves up your web app’s assets.

Start the dev server from the directory that contains your web app’s pubspec.yaml file:

$ cd ~/dart/helloworld
$ pub serve
Serving helloworld on http://localhost:8080

The dev server doesn’t just serve up assets, it produces them by running transformers. A transformer converts input assets (such as Dart files or Polymer-formatted HTML) into output assets (such as JavaScript and HTML).

These output assets aren’t in the file system; they exist only in the dev server. When you’re ready to deploy, generate output files by running pub build.

Pub automatically includes a dart2js transformer that compiles your Dart code to JavaScript. With this, you can change some Dart code, refresh your non-Dartium browser, and immediately see the changes.

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.


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

Optional. Use this option to specify the directories to use as input for the serve command, in addition to lib (which is always processed). The default values are web and test. Directories you might specify typically include the following:
  • benchmark
  • bin
  • example
  • test
  • web
For example, you might specify:
pub serve 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 served because it isn't specified.
Optional. Serves all of the buildable directories (benchmark, bin, example, test, and web) that are present.
Optional. By default, the dev server listens on localhost. You can specify another host using the --hostname option. For example:
$ pub serve --hostname=
Loading source assets... 
Loading markdown_converter transformers... (1.3s)
Serving markdown_converter web on
Build completed successfully
Optional. By default, the dev server uses http://localhost:8080. To change the port number, use the --port option:
$ pub serve --port=9080
Serving helloworld web on http://localhost:9080
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 set to "release" pub generates minified JavaScript using dart2js. Otherwise, it generates unminified JavaScript. Also, in release mode, Pub does not include any source .dart files in the resulting build output since they have been compiled to JavaScript. In any other mode, the raw Dart files are included.

If omitted, it defaults to "debug".