|
1 | | -load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle") |
2 | | - |
3 | 1 | # TODO(alexeagle): promote web_package rule to the public API |
4 | 2 | load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package") |
| 3 | +load("@npm//@babel/cli:index.bzl", "babel") |
5 | 4 | load("@npm//http-server:index.bzl", "http_server") |
6 | 5 | load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") |
| 6 | +load("@npm_bazel_rollup//:index.bzl", "rollup_bundle") |
| 7 | +load("@npm_bazel_terser//:index.bzl", "terser_minified") |
7 | 8 |
|
8 | 9 | rollup_bundle( |
9 | | - name = "bundle", |
| 10 | + name = "chunks", |
10 | 11 | srcs = glob(["*.js"]), |
11 | | - entry_point = ":index.js", |
| 12 | + entry_point = "index.js", |
| 13 | + output_dir = True, |
| 14 | +) |
| 15 | + |
| 16 | +# For older browsers, we'll transform the output chunks to es5 + systemjs loader |
| 17 | +babel( |
| 18 | + name = "chunks_es5", |
| 19 | + args = [ |
| 20 | + "$(location chunks)", |
| 21 | + "--config-file", |
| 22 | + "$(location es5.babelrc)", |
| 23 | + "--out-dir", |
| 24 | + "$@", |
| 25 | + ], |
| 26 | + data = [ |
| 27 | + "chunks", |
| 28 | + "es5.babelrc", |
| 29 | + "@npm//@babel/preset-env", |
| 30 | + ], |
| 31 | + output_dir = True, |
| 32 | +) |
| 33 | + |
| 34 | +# Run terser against both modern and legacy browser chunks |
| 35 | +terser_minified( |
| 36 | + name = "chunks_es5.min", |
| 37 | + src = "chunks_es5", |
| 38 | +) |
| 39 | + |
| 40 | +terser_minified( |
| 41 | + name = "chunks.min", |
| 42 | + src = "chunks", |
12 | 43 | ) |
13 | 44 |
|
14 | 45 | web_package( |
15 | 46 | name = "package", |
| 47 | + # FIXME: need something like: |
| 48 | + # entry_point = "index.js", |
16 | 49 | assets = [ |
17 | | - # For differential loading, we supply both an ESModule entry point and an es5 entry point |
18 | | - # The injector will put two complimentary script tags in the index.html |
19 | | - ":bundle.min.js", |
20 | | - ":bundle.min.es2015.js", |
21 | 50 | "styles.css", |
22 | 51 | ], |
23 | 52 | data = [ |
24 | 53 | "favicon.png", |
25 | | - ":bundle", |
| 54 | + # For differential loading, we supply both ESModule chunks and es5 chunks. |
| 55 | + # The injector will put two complimentary script tags in the index.html |
| 56 | + ":chunks.min", |
| 57 | + ":chunks_es5.min", |
26 | 58 | ], |
27 | 59 | index_html = "index.html", |
28 | 60 | ) |
|
0 commit comments