Skip to content

Commit

Permalink
test: add esbuild(define) tests (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard authored Mar 27, 2023
1 parent 17eac5a commit 50920ae
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/define/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"Demonstrates how to put a banner on output files, see https://esbuild.github.io/api/#banner"

load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")

esbuild(
name = "bundle_production",
define = {
"global": "window",
"OUTPUT_DIR": "\"$(@D)\"",
"RULE_DIR": "\"$(RULEDIR)\"",
"process.env.NODE_ENV": "\"production\"",
},
entry_point = "main.js",
)

# Make sed replacements for consistency on different platform
[
genrule(
name = "sed_{}".format(basename.replace(".", "_")),
srcs = [":{}".format(basename)],
outs = ["sed_{}".format(basename)],
cmd = "sed -E \"s/(\\.\\.\\/.*)?bazel-out\\/.*examples\\//examples\\//\" $(execpath :{}) > $@".format(basename),
)
for basename in [
"bundle_production.js",
]
]

write_source_files(
name = "assertions",
files = {
"bundle_production.expected": "sed_bundle_production.js",
},
)
8 changes: 8 additions & 0 deletions examples/define/bundle_production.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(() => {
// examples/define/main.js
window.DEBUG = false;
console.log("global: ", window);
console.log("OUTPUT_DIR: ", "examples/define");
console.log("RULE_DIR: ", "examples/define");
})();
//# sourceMappingURL=bundle_production.js.map
5 changes: 5 additions & 0 deletions examples/define/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
global.DEBUG = (process.env.NODE_ENV !== 'production')

console.log("global: ", global)
console.log("OUTPUT_DIR: ", OUTPUT_DIR)
console.log("RULE_DIR: ", RULE_DIR)

0 comments on commit 50920ae

Please sign in to comment.