API for running the SWC cli under Bazel
The simplest usage relies on the swcrc
attribute automatically discovering .swcrc
:
load("@aspect_rules_swc//swc:defs.bzl", "swc")
swc(
name = "compile",
srcs = ["file.ts"],
)
swc_compile(name, srcs, data, args, js_outs, map_outs, out_dir, output_dir, plugins, root_dir, source_maps, source_root, swcrc)
Underlying rule for the swc
macro.
Most users should use swc instead, as it predicts the output files and has convenient default values.
Use this if you need more control over how the rule is called,
for example to set your own output labels for js_outs
.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
srcs | source files, typically .ts files in the source tree | List of labels | required | |
data | Runtime dependencies to include in binaries/tests that depend on this target. Follows the same semantics as js_library data attribute. See https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#data for more info. |
List of labels | optional | [] |
args | Additional arguments to pass to swcx cli (NOT swc!). NB: this is not the same as the CLI arguments for @swc/cli npm package. For performance, rules_swc does not call a Node.js program wrapping the swc rust binding. Instead, we directly spawn the (somewhat experimental) native Rust binary shipped inside the @swc/core npm package, which the swc project calls "swcx" Tracking issue for feature parity: swc-project/swc#4017 |
List of strings | optional | [] |
js_outs | list of expected JavaScript output files. There should be one for each entry in srcs. |
List of labels | optional | [] |
map_outs | list of expected source map output files. Can be empty, meaning no source maps should be produced. If non-empty, there should be one for each entry in srcs. |
List of labels | optional | [] |
out_dir | With output_dir=False, output files will have this directory prefix. With output_dir=True, this is the name of the output directory. |
String | optional | "" |
output_dir | Whether to produce a directory output rather than individual files. If out_dir is also specified, it is used as the name of the output directory. Otherwise, the directory is named the same as the target. |
Boolean | optional | False |
plugins | swc compilation plugins, created with swc_plugin rule | List of labels | optional | [] |
root_dir | a subdirectory under the input package which should be consider the root directory of all the input files | String | optional | "" |
source_maps | Create source map files for emitted JavaScript files. see https://swc.rs/docs/usage/cli#--source-maps--s |
String | optional | "false" |
source_root | Specify the root path for debuggers to find the reference source code. see https://swc.rs/docs/usage/cli#--source-root If not set, then the directory containing the source file is used. |
String | optional | "" |
swcrc | label of a configuration file for swc, see https://swc.rs/docs/configuration/swcrc | Label | optional | None |
swc(name, srcs, args, data, plugins, output_dir, swcrc, source_maps, out_dir, root_dir, kwargs)
Execute the SWC compiler
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | A name for this target | none |
srcs | List of labels of TypeScript source files. | none |
args | Additional options to pass to swcx cli, see swc-project/swc#3859 Note: we do not run the NodeJS wrapper @swc/cli |
[] |
data | Files needed at runtime by binaries or tests that transitively depend on this target. See https://bazel.build/reference/be/common-definitions#typical-attributes | [] |
plugins | List of plugin labels created with swc_plugin . |
[] |
output_dir | Whether to produce a directory output rather than individual files. If out_dir is set, then that is used as the name of the output directory. Otherwise, the output directory is named the same as the target. |
False |
swcrc | Label of a .swcrc configuration file for the SWC cli, see https://swc.rs/docs/configuration/swcrc Instead of a label, you can pass a dictionary matching the JSON schema. If this attribute isn't specified, and a file .swcrc exists in the same folder as this rule, it is used.Note that some settings in .swcrc also appear in tsconfig.json . See the notes in [/docs/tsconfig.md]. |
None |
source_maps | If set, the --source-maps argument is passed to the SWC cli with the value. See https://swc.rs/docs/usage/cli#--source-maps--s. True/False are automaticaly converted to "true"/"false" string values the cli expects. | False |
out_dir | The base directory for output files relative to the output directory for this package. If output_dir is True, then this is used as the name of the output directory. |
None |
root_dir | A subdirectory under the input package which should be considered the root directory of all the input files | None |
kwargs | additional keyword arguments passed through to underlying swc_compile , eg. visibility , tags |
none |
swc_plugin(name, srcs, config, kwargs)
Configure an SWC plugin
PARAMETERS