-
Notifications
You must be signed in to change notification settings - Fork 180
/
BUILD
156 lines (138 loc) · 3.39 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package(default_visibility = ["//:__subpackages__"])
load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
### Produce umd, cjs and esm bundles
ts_library(
name = "dev",
srcs = ["index.ts"],
tsickle_typed = True,
deps = ["//src"],
)
[
rollup_bundle(
name = "bundle.%s" % format,
args = args,
config_file = "rollup.config.js",
entry_point = ":index.ts",
format = format,
sourcemap = "true",
deps = [
":dev",
"@npm//@rollup/plugin-buble",
],
)
for format, args in {
"cjs": [],
"esm": [],
"umd": [
# Downlevel (transpile) to ES5.
"-p",
"@rollup/plugin-buble",
],
}.items()
]
genrule(
name = "incremental-dom",
srcs = [":bundle.umd.js"],
outs = ["dist/incremental-dom.js"],
cmd = "cp $(locations :bundle.umd.js) $@",
)
pkg_npm(
name = "npm-umd",
deps = [
":incremental-dom",
],
)
genrule(
name = "incremental-dom-cjs",
srcs = [":bundle.cjs.js"],
outs = ["dist/incremental-dom-cjs.js"],
cmd = "cp $(locations :bundle.cjs.js) $@",
)
pkg_npm(
name = "npm-cjs",
substitutions = {
"const DEBUG = true;": "const DEBUG = process.env.NODE_ENV != \"production\";",
},
deps = [
":incremental-dom-cjs",
],
)
genrule(
name = "incremental-dom-esm",
srcs = [":bundle.esm.js"],
outs = ["dist/incremental-dom-esm.js"],
cmd = "cp $(locations :bundle.esm.js) $@",
)
pkg_npm(
name = "npm-esm",
substitutions = {
"const DEBUG = true;": "const DEBUG = false;",
},
deps = [
":incremental-dom-esm",
],
)
### Produce minified bundle
## Create a second index so that it can have a reference to the release/ directory.
## Using the same index.ts would cause issues with index.closure.js being created twice.
genrule(
name = "release_index",
srcs = ["index.ts"],
outs = ["release_index.ts"],
cmd = "cat $(location index.ts) | sed -e 's/src/release/g' > $@",
)
ts_library(
name = "release",
srcs = [":release_index"],
tsickle_typed = True,
deps = ["//release"],
)
rollup_bundle(
name = "min-bundle",
args = [
# Downlevel (transpile) to ES5.
"-p",
"@rollup/plugin-buble",
],
config_file = "rollup.config.js",
entry_point = ":release_index.ts",
format = "umd",
deps = [
":release",
"@npm//@rollup/plugin-buble",
],
)
## Need to run uglify to minify instead of using .min.es5umd.js, since it uses
## Terser, which has some performance issues with the output in how it inlines
## functions.
genrule(
name = "incremental-dom-min",
srcs = [":min-bundle.js"],
outs = ["dist/incremental-dom-min.js"],
cmd = "$(location node_modules/.bin/uglifyjs) --comments --source-map=url -m -o $@ $(location min-bundle.js)",
tools = ["node_modules/.bin/uglifyjs"],
)
pkg_npm(
name = "npm-min",
deps = [
":incremental-dom-min",
],
)
### Emit TS files
pkg_npm(
name = "npm",
package_name = "incremental-dom",
srcs = [
"index.ts",
"package.json",
"//src:all_files",
],
nested_packages = [
":npm-cjs",
":npm-esm",
":npm-min",
":npm-umd",
],
)