![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@bazel/esbuild
Advanced tools
The esbuild rules runs the esbuild bundler tool with Bazel. esbuild is an extremely fast JavaScript bundler written in Go, its current benchmarks show it can be 320x faster that other bundlers
Add the @bazel/esbuild
npm packages to your devDependencies
in package.json
.
npm install --save-dev @bazel/esbuild
or using yarn
yarn add -D @bazel/esbuild
Add an http_archive
fetching the esbuild binary for each platform that you need to support.
_ESBUILD_VERSION = "0.8.34"
http_archive(
name = "esbuild_darwin",
urls = [
"https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-%s.tgz" % _ESBUILD_VERSION,
],
strip_prefix = "package",
build_file_content = """exports_files(["bin/esbuild"])""",
sha256 = "3bf980b5175df873dd84fd614d57722f3b1b9c7e74929504e26192d23075d5c3",
)
http_archive(
name = "esbuild_windows",
urls = [
"https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-%s.tgz" % _ESBUILD_VERSION,
],
strip_prefix = "package",
build_file_content = """exports_files(["esbuild.exe"])""",
sha256 = "826cd58553e7b6910dd22aba001cd72af34e05c9c3e9af567b5b2a6b1c9f3941",
)
http_archive(
name = "esbuild_linux",
urls = [
"https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-%s.tgz" % _ESBUILD_VERSION,
],
strip_prefix = "package",
build_file_content = """exports_files(["bin/esbuild"])""",
sha256 = "9dff3f5b06fd964a1cbb6aa9ea5ebf797767f1bd2bac71e084fb0bbefeba24a3",
)
These can then be referenced on the tool
attribute of the esbuild
rule.
esbuild(
name = "bundle",
...
tool = select({
"@bazel_tools//src/conditions:darwin": "@esbuild_darwin//:bin/esbuild",
"@bazel_tools//src/conditions:windows": "@esbuild_windows//:esbuild.exe",
"@bazel_tools//src/conditions:linux_x86_64": "@esbuild_linux//:bin/esbuild",
}),
)
It might be useful to wrap this locally in a macro for better reuseability, see packages/esbuild/test/tests.bzl
for an example.
The esbuild
rule can take a JS or TS dependency tree and bundle it to a single file, or split across multiple files, outputting a directory.
load("//@bazel/esbuild:index.bzl", "esbuild")
load("//packages/typescript:index.bzl", "ts_library")
ts_library(
name = "lib",
srcs = ["a.ts"],
)
esbuild(
name = "bundle",
entry_point = "a.ts",
deps = [":lib"],
)
The above will create three output files, bundle.js
, bundle.js.map
and bundle_metadata.json
which contains the bundle metadata to aid in debugging and resoloution tracing.
To create a code split bundle, set splitting = True
on the esbuild
rule.
load("//@bazel/esbuild:index.bzl", "esbuild")
load("//packages/typescript:index.bzl", "ts_library")
ts_library(
name = "lib",
srcs = ["a.ts"],
deps = [
"@npm//foo",
],
)
esbuild(
name = "bundle",
entry_point = "a.ts",
deps = [":lib"],
splitting = True,
)
This will create an output directory containing all the code split chunks, along with their sourcemaps files
USAGE
esbuild(name, args, define, deps, entry_point, external, format, link_workspace_root, minify, output, output_dir, output_map, platform, sources_content, srcs, target, tool)
Runs the esbuild bundler under Bazel
For further information about esbuild, see https://esbuild.github.io/
ATTRIBUTES
(Name, mandatory): A unique name for this target.
(List of strings): A list of extra arguments that are included in the call to esbuild
Defaults to []
(List of strings): A list of global identifier replacements. Example:
esbuild(
name = "bundle",
define = [
"process.env.NODE_ENV=\"production\""
],
)
See https://esbuild.github.io/api/#define for more details
Defaults to []
(List of labels): A list of direct dependencies that are required to build the bundle
Defaults to []
(Label, mandatory): The bundle's entry point (e.g. your main.js or app.js or index.js)
(List of strings): A list of module names that are treated as external and not included in the resulting bundle
See https://esbuild.github.io/api/#external for more details
Defaults to []
(String): The output format of the bundle, defaults to iife when platform is browser and cjs when platform is node. If performing code splitting, defaults to esm.
See https://esbuild.github.io/api/#format for more details
Defaults to ""
(Boolean): Link the workspace root to the bin_dir to support absolute requires like 'my_wksp/path/to/file'. If source files need to be required then they can be copied to the bin_dir with copy_to_bin.
Defaults to False
(Boolean): Minifies the bundle with the built in minification. Removes whitespace, shortens identifieres and uses equivalent but shorter syntax.
Sets all --minify-* flags
See https://esbuild.github.io/api/#minify for more details
Defaults to False
(Label): Name of the output file when bundling
(Boolean): If true, esbuild produces an output directory containing all the output files from code splitting
See https://esbuild.github.io/api/#splitting for more details
Defaults to False
(Label): Name of the output source map when bundling
(String): The platform to bundle for.
See https://esbuild.github.io/api/#platform for more details
Defaults to "browser"
(Boolean): If False, omits the sourcesContent
field from generated source maps
See https://esbuild.github.io/api/#sources-content for more details
Defaults to False
(List of labels): Non-entry point JavaScript source files from the workspace.
You must not repeat file(s) passed to entry_point
Defaults to []
(String): Environment target (e.g. es2017, chrome58, firefox57, safari11, edge16, node10, default esnext)
See https://esbuild.github.io/api/#target for more details
Defaults to "es2015"
(Label, mandatory): An executable for the esbuild binary
3.2.1 (2021-02-23)
--keep-names
(4a26898)FAQs
esbuild rules for Bazel
We found that @bazel/esbuild demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.