Templating new source code
Code generators help teams maintain consistent patterns and standards across a codebase. Instead of manually creating files from scratch, you can use templates to generate standardized components.Example: Using a Yeoman generator
This example uses a Yeoman generator to create a new Fastify route following a predefined template.Run the generator
Run the generator from the Bazel module root (the directory containing This generator uses Yeoman Generator 3, so pin the compatible Yeoman 4 runner shown above. Current Yeoman 7 releases are not compatible with it on Node.js 22.When prompted for a folder, enter Unlike
MODULE.bazel). npx downloads the two packages to its cache and runs them without adding them to your workspace:packages/routes. The generator creates index.js, package.json, and BUILD.bazel in that folder.Open the generated BUILD.bazel. Its main target is an npm_package from rules_js:js_binary, which launches an application, npm_package assembles an npm-compatible directory tree. That tree can be consumed by other Bazel targets or extended later with publishing rules. The generator therefore captures both the source convention and its Bazel packaging boundary.Update the lockfile and build
The new folder matches the starter’s Bazel should report
packages/* workspace pattern. Update only the pnpm lockfile so Bazel discovers the new workspace package, then build it://packages/routes:pkg up to date and write the assembled package under bazel-bin/packages/routes/pkg.
