0.0.17
Pre-releaseUpgrades @rules_prerender
to use @aspect_rules_js
under the hood instead of @build_bazel_rules_nodejs
(see #48). This means applications need to use @aspect_rules_js
-ecosystem rules such as ts_project()
from @aspect_rules_ts
and js_library()
from @aspect_rules_js
. Otherwise the public API is mostly the same, with some minor tweaks to meet the new model.
The rules_prerender
NPM package now only contains the core runtime (PrerenderResource
, includeScript()
, inlineStyle()
, etc.) Published components must now be in their own NPM packages. This means that declarative shadow DOM support is now published under @rules_prerender/declarative_shadow_dom
.
While most of the BUILD rules are relatively unchanged, WORKSPACE
files and the set up experience is very different and noticeably more complicated. We're looking to improve this over time. For now, we must manage deps via both NPM and PNPM (maintain both lockfiles) and include @build_bazel_rules_nodejs
in addition to @aspect_rules_js
. The WORKSPACE
file currently looks like:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "dcc55f810142b6cf46a44d0180a5a7fb923c04a5061e2e8d8eb05ccccc60864b",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.0/rules_nodejs-5.8.0.tar.gz"],
)
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
build_bazel_rules_nodejs_dependencies()
http_archive(
name = "aspect_rules_js",
sha256 = "3ad6684d744ebbc6592d404cc3aa81d0da634eccb3499f6fd198ae122fa28489",
strip_prefix = "rules_js-1.19.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.19.0/rules_js-v1.19.0.tar.gz",
)
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
rules_js_dependencies()
load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
nodejs_register_toolchains(
name = "nodejs",
node_version = "16.10.0",
)
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
npm_install(
name = "npm",
package_json = "//:package.json",
package_lock_json = "//:package-lock.json",
strict_visibility = False,
exports_directories_only = False,
)
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
npm_translate_lock(
name = "npm_user",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
npmrc = "//:.npmrc",
)
load("@npm_user//:repositories.bzl", "npm_repositories")
npm_repositories()
# This _must_ be named `rules_prerender`, other names are currently unsupported.
http_archive(
name = "rules_prerender",
sha256 = "8797660276fb25fde3545a44cda723042dd7d503cbdbe32710ac55439131ffce",
strip_prefix = "rules_prerender-releases-0.0.17",
url = "https://github.com/dgp1130/rules_prerender/archive/refs/tags/releases/0.0.17.tar.gz",
)
load("@rules_prerender//:dependencies.bzl", "rules_prerender_dependencies")
rules_prerender_dependencies()
load("@rules_prerender//:repositories.bzl", "rules_prerender_repositories")
rules_prerender_repositories()
load(
"@rules_prerender//:npm_repositories.bzl",
prerender_npm_repositories = "npm_repositories",
)
prerender_npm_repositories()
Again, we're hoping to simplify this in the future, primarily by moving entirely off @build_bazel_rules_nodejs
.
As for BUILD
file changes, the most notable one is that using published components requires a link_prerender_component()
much like npm_link_package()
. In the root BUILD
file, include:
load("@npm_user//:defs.bzl", "npm_link_all_packages")
load("@rules_prerender//:index.bzl", "link_prerender_component")
# Make sure to `pnpm install` any published components.
npm_link_all_packages(name = "node_modules")
# Link each NPM package containing a prerender component.
link_prerender_component(
name = "prerender_components/@rules_prerender/declarative_shadow_dom",
package = ":node_modules/@rules_prerender/declarative_shadow_dom",
visibility = ["//visibility:public"],
)
Then depend on the //:prerender_components/*
target in the deps
of any prerender_component()
like so:
load("@rules_prerender//:index.bzl", "prerender_component")
prerender_component(
name = "component",
srcs = ["component.ts"],
deps = ["//:prerender_components/@rules_prerender/declarative_shadow_dom"],
)