| load("//:index.bzl", "generated_file_test") |
| load("//packages/esbuild:index.bzl", "esbuild") |
| load("//packages/concatjs:index.bzl", "ts_library") |
| |
| ts_library( |
| name = "index", |
| srcs = ["index.ts"], |
| module_name = "lib", |
| ) |
| |
| ts_library( |
| name = "lib", |
| package_name = "lib", |
| srcs = ["a.ts"], |
| deps = [":index"], |
| ) |
| |
| esbuild( |
| name = "bundle", |
| args = { |
| "keepNames": True, |
| # ensure that esbuild prefers .mjs to .js if both are available |
| # since ts_library produces both |
| "resolveExtensions": [ |
| ".mjs", |
| ".js", |
| ], |
| }, |
| entry_point = "a.ts", |
| deps = [":lib"], |
| ) |
| |
| esbuild( |
| name = "bundle.min", |
| args = { |
| "keepNames": True, |
| # ensure that esbuild prefers .mjs to .js if both are available |
| # since ts_library produces both |
| "resolveExtensions": [ |
| ".mjs", |
| ".js", |
| ], |
| }, |
| entry_point = "a.ts", |
| minify = True, |
| deps = [":lib"], |
| ) |
| |
| esbuild( |
| name = "bundle.split", |
| args = { |
| "keepNames": True, |
| # ensure that esbuild prefers .mjs to .js if both are available |
| # since ts_library produces both |
| "resolveExtensions": [ |
| ".mjs", |
| ".js", |
| ], |
| }, |
| entry_point = "a.ts", |
| output_dir = True, |
| deps = [":lib"], |
| ) |
| |
| # esbuild will put the filepath in a comment within the non-minified file, |
| # on different platforms this will cause the golden test to differ |
| # strip the platform agnostic part of it |
| # note that this regex doesn't strip the sourcemap URI comment |
| genrule( |
| name = "strip_bundle_comments", |
| srcs = ["bundle.js"], |
| outs = ["bundle.stripped.js"], |
| cmd = "cat $(location :bundle.js) | sed \"s#// .*##\" > $@", |
| ) |
| |
| generated_file_test( |
| name = "bundle_test", |
| src = "bundle.golden.txt", |
| generated = "bundle.stripped.js", |
| ) |
| |
| generated_file_test( |
| name = "bundle_min_test", |
| src = "bundle.min.golden.txt", |
| generated = "bundle.min.js", |
| ) |