Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Running a devserver under Bazel

Alex Eagle edited this page Apr 24, 2018 · 1 revision

ts_devserver

rules_typescript includes a minimal development server called ts_devserver which you invoke by calling a Bazel rule of the same name. This server is intended to get you started, or may be sufficient for a simple frontend application.

ts_devserver illustrates several important principles of a devserver running under Bazel:

  • It is started with ibazel run, so that the build system watches your source files and quickly keeps the application up-to-date as you make changes.
  • It does not restart when the application changes. It uses a Bazel tag ibazel_notify_changes to tell ibazel to leave the binary running. ibazel will write to the program's stdin to tell it when the application changed.
  • On each request, it always reads files from the bazel-bin folder, so that the application is served up-to-date.
  • We do not bundle the .js files in the build system. This would always be re-run when any JS file changes, and prevents us doing some clever caching.
  • Instead, we use a named AMD module format that allows us to quickly concatenate the sources on the fly. It's important even as the application grows very large that you don't exceed the 2s dev round-trip-time. Concatenation takes about 200ms to re-bundle 10,000 small source files when one of them changes.
  • The concat library is implemented in Go (https://github.com/bazelbuild/rules_typescript/tree/master/internal/concatjs) and in JavaScript (https://github.com/bazelbuild/rules_typescript/blob/master/internal/karma/index.ts) - we expect that shared implementations in other languages will be written and open-sourced by the community.
  • The devserver also uses a Bazel tag ibazel_live_reload which tells it whether the user has opted-out from having their browser auto-refresh when the application changes. It injects the livereload client script into the served JavaScript.

Your devserver

ts_devserver is very convenient. However if you do full-stack development and have a real backend, we recommend running that server in development mode as well. You don't want to lose the properties described above, however.

Please read through that list and ensure that your development server has as many of these properties as possible. Ideally we should have an example for each popular server so it's easier for you to configure.

Clone this wiki locally