Skip to content

Latest commit

 

History

History
116 lines (84 loc) · 2.49 KB

README.md

File metadata and controls

116 lines (84 loc) · 2.49 KB

rules_javascript

Build

Bazel rules for JavaScript, TypeScript, and related technologies.

Documentation

See documentation.

Philosophy

  1. Flexibility and extensibility
  2. Performance
  3. Bazel idioms
  4. Clear separation of concerns

Install

WORKSPACE.bazel

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# skylib

SKYLIB_VERSION = "16de038c484145363340eeaf0e97a0c9889a931b"
http_archive(
    name = "bazel_skylib",
    sha256 = "96e0cd3f731f0caef9e9919aa119ecc6dace36b149c2f47e40aa50587790402b",
    strip_prefix = "bazel-skylib-%s" % SKYLIB_VERSION,
    urls = ["https://github.com/bazelbuild/bazel-skylib/archive/%s.tar.gz" % SKYLIB_VERSION],
)

# better_rules_javascript

JAVACRIPT_VERSION = "..."
http_archive(
    name = "better_rules_javascript",
    strip_prefix = "rules_javascript-%s" % JAVASCRIPT_VERSION,
    urls = ["https://github.com/rivethealth/rules_javascript/archive/%s.tar.gz" % JAVACRIPT_VERSION],
)

load("@better_rules_javascript//rules:workspace.bzl", javascript_repositories = "respositories")
javascript_respositories()

Example

main.ts

console.log("Hello world");

tsconfig.json

{ "compilerOptions": { "lib": ["dom"] } }

BUILD.bazel

load("@better_rules_javascript//commonjs:rules.bzl", "cjs_root")
load("@better_rules_javascript//javascript:rules.bzl", "js_library")
load("@better_rules_javascript//typescript:rules.bzl", "tsconfig", "ts_library")
load("@better_rules_javascript//nodejs:rules.bzl", "nodejs_binary")

nodejs_binary(
    name = "bin",
    dep = ":lib",
    main = "main.js",
)

ts_library(
    name = "lib",
    config = ":tsconfig",
    root = ":root",
    srcs = ["main.ts"],
    deps = [":lib"],
)

cjs_root(
  name = "root",
  package_name = "example",
)

js_library(
    name = "tsconfig",
    root = ":root",
    srcs = ["tsconfig.json"],
)

Running:

$ bazel run //:bin
Hello world

Developing

See DEVELOPING.md.