Skip to content

Commit

Permalink
Adds Preact support to @rules_prerender/declarative_shadow_dom.
Browse files Browse the repository at this point in the history
Refs #71.

This adds a new `/preact.mjs` entry point which is implemeted via an optional peer dep on `@rules_prerender/preact`.

I tried adding `exports` to specifically support jsut `/preact.mjs`, but unfortunately that requires `moduleResolution: "Node16"` in `tsconfig.json` which introduces a whole bunch of other problems I don't want to deal with at the moment.
  • Loading branch information
dgp1130 committed Mar 13, 2023
1 parent e0bc134 commit e505ac2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/preact/component/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ prerender_component(
"//:node_modules/@rules_prerender/preact",
"//:node_modules/preact",
],
deps = ["//:prerender_components/@rules_prerender/declarative_shadow_dom"],
)

ts_project(
Expand Down
2 changes: 2 additions & 0 deletions examples/preact/component/component.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { polyfillDeclarativeShadowDom } from '@rules_prerender/declarative_shadow_dom/preact.mjs';
import { Template, includeScript, inlineStyle } from '@rules_prerender/preact';
import { ComponentChildren, VNode } from 'preact';

Expand All @@ -19,6 +20,7 @@ export function Component({ text, children }: {
<div id="replace">This text to be replaced by page JavaScript.</div>
<slot></slot>

{polyfillDeclarativeShadowDom()}
{includeScript('./script.mjs', import.meta)}
{inlineStyle('./style.css', import.meta)}
</Template>
Expand Down
11 changes: 9 additions & 2 deletions packages/declarative_shadow_dom/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ npm_publish(

prerender_component(
name = "declarative_shadow_dom",
srcs = ["declarative_shadow_dom.mts"],
srcs = [
"declarative_shadow_dom.mts",
"preact.mts",
],
tsconfig = "//:tsconfig",
source_map = True,
scripts = [":declarative_shadow_dom_polyfill"],
lib_deps = ["//:node_modules/rules_prerender"],
lib_deps = [
"//:node_modules/@rules_prerender/preact",
"//:node_modules/preact",
"//:node_modules/rules_prerender",
],
visibility = [
"//:__pkg__",
"//packages/rules_prerender:__pkg__",
Expand Down
6 changes: 6 additions & 0 deletions packages/declarative_shadow_dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"type": "module",
"main": "./declarative_shadow_dom.mjs",
"peerDependencies": {
"@rules_prerender/preact": "^0.0.0-PLACEHOLDER",
"rules_prerender": "^0.0.0-PLACEHOLDER"
},
"peerDependenciesMeta": {
"@rules_prerender/preact": {
"optional": true
}
}
}
10 changes: 10 additions & 0 deletions packages/declarative_shadow_dom/preact.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { includeScript } from '@rules_prerender/preact';
import type { VNode } from 'preact';

/**
* Returns a prerender annotation used by the bundler to inject the declarative
* shadow DOM polyfill into the document.
*/
export function polyfillDeclarativeShadowDom(): VNode {
return includeScript('./declarative_shadow_dom_polyfill.mjs', import.meta);
}

0 comments on commit e505ac2

Please sign in to comment.