Node.js is most common execution environment outside a web browser.
package.json
{}
main.js
console.log("Hello world");
BUILD.bazel
load("@better_rules_javascript//commonjs:rules.bzl", "cjs_root")
load("@better_rules_javascript//javascript:rules.bzl", "js_library")
load("@better_rules_javascript//nodejs:rules.bzl", "nodejs_binary")
cjs_root(
name = "root",
descriptor = "package.json",
package_name = "example",
)
js_library(
name = "main",
root = ":root",
srcs = ["main.js"],
)
nodejs_binary(
name = "bin",
dep = ":main",
main = "main.js",
)
Then
$ bazel run //:bin
Hello world
IDEs use node_modules
. To install external dependencies or link local files:
BUILD.bazel
load("@better_rules_javascript//nodejs:rules.bzl", "nodejs_install", "nodejs_modules_package")
nodejs_install(
name = "nodejs_install",
src = ":node_modules",
)
nodejs_modules_package(
name = "node_modules",
deps = ["@npm//external-example:lib"],
links = ["//internal-example:root"],
)
Then run:
bazel run :nodejs_install
NodejsInfo(bin, options)
Node.js executable information.
FIELDS
Name | Description |
---|---|
bin | Node.js executable |
options | Node.js options |
NodejsRuntimeInfo(bin)
Node.js runtime.
FIELDS
Name | Description |
---|---|
bin | Node.js executable |
nodejs_runtime_rule(name)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | - |
none |
nodejs(name, options, runtime)
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
options | - | List of strings | optional | [] |
runtime | - | Label | required |
nodejs_binary(name, data, dep, env, main, node, node_options)
Node.js binary
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
data | Runtime data | List of labels | optional | [] |
dep | JavaScript library. | Label | required | |
env | Environment variables | Dictionary: String -> String | optional | {} |
main | - | String | required | |
node | - | Label | optional | :nodejs |
node_options | Node.js options | List of strings | optional | [] |
nodejs_binary_package(name, dep, env, main, node, node_options)
Create executable tar
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
dep | - | Label | required | |
env | Environment variables | Dictionary: String -> String | optional | {} |
main | - | String | required | |
node | - | Label | optional | :nodejs |
node_options | Node.js options | List of strings | optional | [] |
nodejs_modules_binary(name, env, main, main_package, modules, node, node_options, path)
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
env | - | Dictionary: String -> String | optional | {} |
main | - | String | optional | "" |
main_package | - | String | required | |
modules | - | Label | required | |
node | - | Label | optional | :nodejs |
node_options | - | List of strings | optional | [] |
path | - | String | optional | "" |
nodejs_modules_package(name, deps, links)
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
deps | - | List of labels | optional | [] |
links | - | List of labels | optional | [] |
nodejs_simple_binary(name, node, node_options, path, src)
Node.js executable, from a single file.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
node | - | Label | required | |
node_options | - | List of strings | optional | [] |
path | Path to file, if src is directory | Label | optional | None |
src | Source file | Label | required |
nodejs_system_runtime(name, node)
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
node | - | String | required |
nodejs_toolchain(name, bin)
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
bin | Node.js executable | Label | required |
configure_nodejs_runtime(name, repo_name, nodejs_runtime_rule, visibility)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | - |
none |
repo_name | - |
none |
nodejs_runtime_rule | - |
none |
visibility | - |
None |
nodejs_install(name, src, path, kwargs)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | - |
none |
src | - |
none |
path | - |
None |
kwargs | - |
none |
nodejs_modules(name, deps, kwargs)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | - |
none |
deps | - |
none |
kwargs | - |
none |
nodejs_repositories(name, repositories)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | - |
none |
repositories | - |
none |
nodejs_toolchains(toolchain, repositories)
PARAMETERS
Name | Description | Default Value |
---|---|---|
toolchain | - |
none |
repositories | - |
none |