You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/typescript/docs/install.md
+70Lines changed: 70 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,45 @@ The TypeScript rules integrate the TypeScript compiler with Bazel.
7
7
Looking for Karma rules `ts_web_test` and `karma_web_test`?
8
8
These are now documented in the README at https://npmjs.com/package/@bazel/karma
9
9
10
+
## Alternatives
11
+
12
+
This package provides Bazel wrappers around the TypeScript compiler, and are how we compile TS code at Google.
13
+
14
+
These rules are opinionated, for example:
15
+
16
+
- Your TS code must compile under the `--declaration` flag so that downstream libraries depend only on types, not implementation. This makes Bazel faster by avoiding cascading rebuilds in cases where the types aren't changed.
17
+
- We control the output format and module syntax so that downstream rules can rely on them.
18
+
19
+
They are also fast and optimized:
20
+
21
+
- We keep a running TypeScript compile running as a daemon, using Bazel workers. This process avoids re-parse and re-JIT of the >1MB `typescript.js` and keeps cached bound ASTs for input files which saves time.
22
+
23
+
We understand this is a tradeoff. If you want to use the plain TypeScript compiler provided by the TS team at Microsoft, you can do this by calling its CLI directly. For example,
24
+
25
+
```python
26
+
load("@npm//typescript:index.bzl", "tsc")
27
+
28
+
srcs = glob(["*.ts"])
29
+
deps = ["@npm//@types/node"]
30
+
31
+
tsc(
32
+
name="compile",
33
+
data= srcs + deps,
34
+
outs= [s.replace(".ts", ext) for ext in [".js", ".d.ts"] for s in srcs],
35
+
args= [
36
+
"--outDir",
37
+
"$@",
38
+
"--lib",
39
+
"es2017,dom",
40
+
"--downlevelIteration",
41
+
"--declaration",
42
+
] + [
43
+
"$(location %s)"% s
44
+
for s in srcs
45
+
],
46
+
)
47
+
```
48
+
10
49
## Installation
11
50
12
51
Add a devDependency on `@bazel/typescript`
@@ -208,6 +247,37 @@ directory. See the notes about the `tsconfig` attribute in the [ts_library API d
208
247
209
248
[ts_library API docs]: http://tsetse.info/api/build_defs.html#ts_library
210
249
250
+
## Accessing JavaScript outputs
251
+
252
+
The default output of the `ts_library` rule is the `.d.ts` files.
253
+
This is for a couple reasons:
254
+
255
+
- help ensure that downstream rules which access default outputs will not require
256
+
a cascading re-build when only the implementation changes but not the types
257
+
- make you think about whether you want the devmode (named UMD) or prodmode outputs
258
+
259
+
You can access the JS output by adding a `filegroup` rule after the `ts_library`,
0 commit comments