Skip to main content
This comprehensive training course will guide you through building modern JavaScript and TypeScript applications with Bazel. The JavaScript ecosystem moves quickly. New tools pop up monthly, and many of them evolve to be build systems, either intentionally or accidentally. The Aspect team has been developing Bazel support for JavaScript since 2017. As the industry experts we’re excited to show you how well this tooling can work for your team. rules_nodejs commit history Before you begin, ensure you have completed the Bazel 101 course to understand the core Bazel concepts. Now, let’s get started.

Tooling

This guide uses a combination of Bazel modules and performance-optimized tools.

Bazel modules

The following modules form the foundation of the JavaScript toolchain within Bazel:
  • Runtime environment — The rules_nodejs module supplies a fully isolated node.js toolchain, both for running build tools and for server application runtimes.
  • JavaScript rules and package management — The aspect_rules_js module translates a pnpm lockfile into Bazel targets and supplies the basic rules for building, testing, packaging, and running JavaScript code.
  • TypeScript support — The aspect_rules_ts module adds type-checking and transpilation to JavaScript.

rules_js features used in this course

You will use rules_js at each layer of the application:
  • npm_translate_lock turns the pnpm lockfile into the external @npm repository, while npm_link_all_packages gives each workspace package a strict, package-local node_modules target.
  • js_binary runs an entry point with Bazel’s hermetic Node.js toolchain and a declared set of runtime files.
  • Generated npm bin macros expose tools such as Vite as ordinary Bazel executables.
  • js_library carries JavaScript sources and generated outputs through the build graph, while npm_package assembles an npm-compatible package tree.
  • js_run_devserver keeps a development server alive, synchronizes declared files into its sandbox, and cooperates with iBazel for watch mode.
These rules preserve familiar npm and pnpm workflows while making their inputs visible to Bazel, which is what enables caching, parallel execution, and reproducible builds.

Performance optimized build tools

Bazel works with virtually any JavaScript tooling. However, you will experience the best performance with tools that have minimal startup time. This guide uses Rust-based tools where it can:
  • SWC: A fast Rust-based tool for transpiling JavaScript/TypeScript. The starter repository uses it for ts_project targets, leaving tsc to type-check only.
  • Vite: A modern development server that provides a fast development experience.
    The native Go port of the TypeScript compiler ships as TypeScript 7. aspect_rules_ts 3.9.0 and later can run the TypeScript 7 release candidate, so type-checking gets faster without changing your BUILD files.

Development experience

Finally, install the Aspect CLI to improve the terminal workflow. It makes Bazel easier to use by providing a familiar task-runner interface similar to package.json scripts. Next, you’ll build a basic Node.js application with Bazel.
zipline

Delivered by Zipline

Sponsorship for development of this training course was provided by Zipline. Thank you!