This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BUILD
69 lines (64 loc) · 1.88 KB
/
BUILD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
load("@aspect_rules_swc//swc:swc.bzl", swc = "swc_rule")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@bazel_skylib//lib:partial.bzl", "partial")
load("babel.bzl", "babel")
load("@npm//@bazel/typescript:index.bzl", "ts_project")
# Create a test fixture that is a non-trivial sized TypeScript program
write_file(
name = "gen_ts",
out = "big.ts",
content = [
"export const a{0}: number = {0}".format(x)
for x in range(100000)
],
)
_TSCONFIG = {
"compilerOptions": {
"declaration": True,
"sourceMap": True,
},
}
# Uses TypeScript (tsc) for both type-checking and transpilation
# % bazel build tsc
# INFO: Elapsed time: 6.798s, Critical Path: 5.24s
ts_project(
name = "tsc",
srcs = ["big.ts"],
out_dir = "build-tsc",
tsconfig = _TSCONFIG,
)
# Runs swc to transpile ts -> js
# and tsc to type-check.
# % bazel build swc
# INFO: Elapsed time: 0.745s, Critical Path: 0.54s
#
# Optionally, or on CI, you can explicitly do the slow type-check:
# $ bazel build swc_typecheck
# INFO: Elapsed time: 3.330s, Critical Path: 3.19s
ts_project(
name = "swc",
# Partial allows us to apply some arguments here, while ts_project applies the rest.
# See https://en.wikipedia.org/wiki/Partial_application
# and https://docs.aspect.dev/bazelbuild/bazel-skylib/1.1.1/docs/partial.html
transpiler = partial.make(
swc,
# Attributes to the swc rule can appear here
args = ["--env-name=test"],
),
srcs = ["big.ts"],
out_dir = "build-swc",
tsconfig = _TSCONFIG,
)
# Runs babel to transpile ts -> js
# and tsc to type-check
# % bazel build babel
# INFO: Elapsed time: 3.928s, Critical Path: 3.73s
#
# Like the swc example, you could build babel_typecheck to run tsc.
ts_project(
name = "babel",
transpiler = babel,
srcs = ["big.ts"],
out_dir = "build-babel",
tsconfig = _TSCONFIG,
)