@@ -16,31 +16,30 @@ or using yarn
16
16
yarn add -D @bazel/esbuild
17
17
```
18
18
19
- The esbuild binary is fetched from npm automatically and exposed via toolchains. Add the `esbuild_repositories` rule to the `WORKSPACE`:
19
+ The esbuild binary is fetched automatically for your platform and is exposed via Bazel toolchains.
20
+ To do this, add the `esbuild_repositories` rule to your `WORKSPACE`.
21
+ You'll need to point it to the repository created by npm_install or yarn_install where the `@bazel/esbuild`
22
+ package is fetched. (Typically, this is `npm`).
23
+ Set the `npm_repository` attribute to the name of that repository.
20
24
21
25
```python
22
- load("@npm//@bazel/esbuild:esbuild_repositories.bzl", "esbuild_repositories")
23
-
24
- esbuild_repositories()
25
- ```
26
-
27
- As esbuild is being fetched from `npm`, the load statement above can cause eager fetches of the `@npm` external repository.
28
- To work around this, it's possible to fetch the `@bazel/esbuild` package via an `http_archive`
29
-
30
- ```python
31
- http_archive(
32
- name = "bazel_esbuild",
33
- urls = [
34
- "https://registry.npmjs.org/@bazel/esbuild/-/esbuild-4.0.0.tgz",
35
- ],
36
- strip_prefix = "package",
26
+ npm_install(
27
+ name = "npm",
28
+ # @bazel/esbuild is a dependency in this package.json
29
+ package_json = "//:package.json",
30
+ package_lock_json = "//:package-lock.json",
37
31
)
38
32
39
- load("@bazel_esbuild// :esbuild_repositories.bzl", "esbuild_repositories")
33
+ load("@build_bazel_rules_nodejs//toolchains/esbuild :esbuild_repositories.bzl", "esbuild_repositories")
40
34
41
- esbuild_repositories()
35
+ esbuild_repositories(npm_repository = "npm") # Note, npm is the default value for npm_repository
42
36
```
43
37
38
+ > To avoid eagerly fetching all the npm dependencies, this load statement comes from the "Built-in"
39
+ > `@build_bazel_rules_nodejs` repository rather than from `@npm`.
40
+ > In rules_nodejs 5.0 we intend to fix this layering violation by having the whole esbuild support
41
+ > distributed independently of rules_nodejs, and not require any package to be installed from npm.
42
+
44
43
## Overview
45
44
46
45
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.
@@ -97,11 +96,11 @@ load(
97
96
_esbuild_config = "esbuild_config" ,
98
97
)
99
98
load (
100
- "@build_bazel_rules_nodejs//packages /esbuild:esbuild_repositories.bzl" ,
99
+ "@build_bazel_rules_nodejs//toolchains /esbuild:esbuild_repositories.bzl" ,
101
100
_esbuild_repositories = "esbuild_repositories" ,
102
101
)
103
102
load (
104
- "@build_bazel_rules_nodejs//packages /esbuild/toolchain :toolchain.bzl" ,
103
+ "@build_bazel_rules_nodejs//toolchains /esbuild:toolchain.bzl" ,
105
104
_configure_esbuild_toolchain = "configure_esbuild_toolchain" ,
106
105
)
107
106
0 commit comments