A simple Dart development server that serves a web app, automatically refreshes when there's a change, and is compatible with single page apllications (SPA) that utilize the history API.
The implementation of this package is just a proxy server that passes requests to
package: build_runner. So, it needs to be installed along with this package.
dev_dependencies: build_runner: build_web_compilers: livereload: ^0.2.0
pub get --no-precompile
pub run livereload
Then, browse your web app at http://localhost:8000.
If you are going to build an SPA, make sure to add a proper
<base> so that your routing works.
<!DOCTYPE html> <html lang="en"> <head> <!-- <base> is needed. --> <base href="/"> <script defer src="main.dart.js"></script> <title>SPA</title> </head> <body> <!-- AngularDart with angular_router --> <my-app>Loading...</my-app> </body> </html>
Command Line Options
Since this runs
pub run build_runner serve under the hood, some options replicates those of
pub run livereload [directory] [options]
By default, the directory is
web. Please note that this package does not support serving more than one directory at a time, because it would complicate the CLI options. If it is needed, please file an issue. Furthermore, PRs are welcome.
- -l, --low-resources-mode: Reduces the amount of memory consumed by the build process.
- -c, --config: Reads
build.<name>.yamlinstead of the default
build_runner >= 0.7.8)
- --define: Sets the global
optionsconfig for a builder by key. As an example, enabling the dart2js compiler would look like:
build_runner >= 0.7.9)
- --hostname: Specifies the hostname to serve on. (defaults to "localhost")
- --buildport: Changes the port number where
build_runnerserves. (defaults to "8080")
- --proxyport: Changes the port number of the proxy server. (defaults to "8000")
- --websocketport: Changes the port number of the websocket. (defaults to "4242")
- --[no-]spa: Serves a single page application. This allows routes controlled by history API to be working. (defaults to on)
Some of the options from
package: build_runner are intentionally left out, since it wouldn't match the use case of this package.