Pages

Saturday, May 23, 2015

Custom Bazel build rules to compile TypeScript

I've written a Skylark module for Bazel to compile TypeScript projects. Source code and example build files are available at https://github.com/zmxv/bazel-custom-rules.

Two new rules are introduced by typescript.bzl: ts_library (to group TypeScript modules) and ts_binary (to compile TypeScript sources into a single JavaScript file). Additional compiler options may be passed to tsc via the optional flags attribute as shown below.

ts_library(
  name = "externs",
  srcs = ["externs.d.ts"],
)

ts_library(
  name = "common",
  srcs = ["common.ts"],
  deps = [":externs"],
)

ts_binary(
  name = "main"
  srcs = ["main.ts"],
  deps = [":common"],
  flags = [
      "--removeComments",
      "--noEmitOnError",
  ],
)

No comments:

Post a Comment