Skip to content

Example JS/TS repository using Bazel for building

License

Notifications You must be signed in to change notification settings

Kartones/bazel-web-template

Repository files navigation

bazel-web-template

Setup

Run

To invoke all example runnable targets:

make run

Development

To build:

bazelisk build //...

Note that run and test also build/rebuild whatever is needed.

Rule wrappers

Most external rules are wrapped at rules folder, so they can be modified, refactored or simplified at will.

If an external rule is only used inside other rules/macros and not from BUILD files, initially there's no need of wrapping them.

Setup

Each time dependencies change/get updated, run pnpm install (toolchains use pnpm-lock.yaml).

Note: The NodeJS & Typescript versions you should use are dictated by rules_js and rules_ts. You can see more details, and where to check which versions are available, if you inspect the WORKSPACE file, I left some comments there.

Development Requirements

Note: package.json maximum versions are mandated from the toolchains. Check the WORKSPACE file for more details.

For pnpm, alternatively can use the rules_js provisioned one, e.g.:

bazelisk run @pnpm//:pnpm -- --dir $PWD outdated

But note that you'll need to instruct it extra configuration (runs from a sandbox).

Recommendations

Testing

Run the Bazel way. Can run all the tests:

bazelisk test //...

Also created a make target:

make test

Or filter by tags:

bazelisk test //... --test_tag_filters=js

All test flags/options are valid.

Writing Tests

Tests are written using only NodeJS testing capabilities.

Querying

  • List all output files from a label:
bazelisk cquery --output=files //src/js:a
bazelisk cquery --output=files //src/ts:c

TODO

  • more query examples
  • linting?
  • @bazel/ibazel?