API for running SWC under Bazel

Simplest usage:

load("@aspect_rules_swc//swc:defs.bzl", "swc")

swc(name = "transpile")

Known issues:

Rules

swc_transpiler

Underlying rule for the swc macro.

Most users should just use swc instead.

Use this if you need more control over how the rule is called, for example to set your own output labels for js_outs.

This rule is also suitable for the ts_project#transpiler attribute.

Example usage (generated)

load("@rules_swc//swc:defs.bzl", "swc_transpiler")

swc_transpiler(
    # A unique name for this target.
    name = "",
    # source files, typically .ts files in the source tree
    srcs = [],
)

name

A unique name for this target.

args

additional arguments to pass to swc cli, see https://swc.rs/docs/usage/cli

data

Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the data attribute are added to the runfiles of this taregt. Thery should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from npm_package_stores and transitive_npm_package_stores fields of these and for linked npm package targets, from the underlying npm_package_store target(s) that back the links via npm_linked_packages and transitive_npm_linked_packages.

Gathered NpmPackageStoreInfo providers are used downstream as direct dependencies when linking a downstream npm_package target with npm_link_package.

js_outs

list of expected JavaScript output files.

There must be one for each entry in srcs, and in the same order.

map_outs

list of expected source map output files.

Can be empty, meaning no source maps should be produced. If non-empty, there must be one for each entry in srcs, and in the same order.

out_dir

base directory for output files

output_dir

whether to produce a directory output rather than individual files

source_maps

see https://swc.rs/docs/usage/cli#--source-maps--s

srcs

source files, typically .ts files in the source tree

swc_cli

binary that executes the swc CLI

swcrc

label of a configuration file for swc, see https://swc.rs/docs/configuration/swcrc


Macros and Functions

swc

Execute the swc compiler

Example usage (generated)

load("@rules_swc//swc:defs.bzl", "swc")

swc(
    # A name for the target
    name = "",
)

name

A name for the target

srcs

source files, typically .ts files in the source tree

args

additional arguments to pass to swc cli, see https://swc.rs/docs/usage/cli

data

runtime dependencies to be propagated in the runfiles

output_dir

whether to produce a directory output rather than individual files

swcrc

label of a configuration file for swc, see https://swc.rs/docs/configuration/swcrc

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.

out_dir

base directory for output files relative to the output directory for this package

kwargs

additional named parameters like tags or visibility