From b6b8484880f2024f65f64b94b4211be65c49aa1e Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Fri, 21 Jul 2023 19:42:13 -0700 Subject: [PATCH] Adds rewrite example. Refs #40. This uses `prerender_component2` and friends. It is a temporary example for testing the rewrite and will probably be deleted once the rest of the repository is migrated to the new implementation. --- examples/rewrite/BUILD.bazel | 23 +++++++++++ examples/rewrite/component/BUILD.bazel | 39 ++++++++++++++++++ .../rewrite/component/component.client.mts | 1 + examples/rewrite/component/component.css | 3 ++ .../rewrite/component/component.prerender.tsx | 20 +++++++++ examples/rewrite/component/image.png | Bin 0 -> 9948 bytes examples/rewrite/site.prerender.tsx | 18 ++++++++ examples/rewrite/transitive/BUILD.bazel | 14 +++++++ .../transitive/transitive.prerender.tsx | 7 ++++ 9 files changed, 125 insertions(+) create mode 100644 examples/rewrite/BUILD.bazel create mode 100644 examples/rewrite/component/BUILD.bazel create mode 100644 examples/rewrite/component/component.client.mts create mode 100644 examples/rewrite/component/component.css create mode 100644 examples/rewrite/component/component.prerender.tsx create mode 100644 examples/rewrite/component/image.png create mode 100644 examples/rewrite/site.prerender.tsx create mode 100644 examples/rewrite/transitive/BUILD.bazel create mode 100644 examples/rewrite/transitive/transitive.prerender.tsx diff --git a/examples/rewrite/BUILD.bazel b/examples/rewrite/BUILD.bazel new file mode 100644 index 00000000..2554e212 --- /dev/null +++ b/examples/rewrite/BUILD.bazel @@ -0,0 +1,23 @@ +load("//:index.bzl", prerender_pages = "prerender_pages2", "web_resources_devserver") +load("//tools/typescript:defs.bzl", "ts_project") + +prerender_pages( + name = "site", + entry_point = "./site.prerender.js", + prerender = ":prerender", +) + +web_resources_devserver( + name = "devserver", + resources = ":site", +) + +ts_project( + name = "prerender", + srcs = ["site.prerender.tsx"], + deps = [ + "//examples/rewrite/component:component_prerender", + "//:node_modules/@rules_prerender/preact", + "//:node_modules/preact", + ], +) diff --git a/examples/rewrite/component/BUILD.bazel b/examples/rewrite/component/BUILD.bazel new file mode 100644 index 00000000..1f89395b --- /dev/null +++ b/examples/rewrite/component/BUILD.bazel @@ -0,0 +1,39 @@ +load("//:index.bzl", "css_library", prerender_component = "prerender_component2", "web_resources") +load("//tools/typescript:defs.bzl", "ts_project") + +prerender_component( + name = "component", + prerender = ":prerender", + scripts = ":scripts", + styles = ":styles", + resources = ":resources", + visibility = ["//examples/rewrite:__subpackages__"], +) + +ts_project( + name = "prerender", + srcs = ["component.prerender.tsx"], + deps = [ + "//examples/rewrite/transitive:transitive_prerender", + "//:node_modules/@rules_prerender/preact", + "//:node_modules/preact", + "//:prerender_components/@rules_prerender/declarative_shadow_dom_prerender", + ], +) + +ts_project( + name = "scripts", + srcs = ["component.client.mts"], +) + +css_library( + name = "styles", + srcs = ["component.css"], +) + +web_resources( + name = "resources", + entries = { + "/logo.png": "image.png", + }, +) diff --git a/examples/rewrite/component/component.client.mts b/examples/rewrite/component/component.client.mts new file mode 100644 index 00000000..eb065f93 --- /dev/null +++ b/examples/rewrite/component/component.client.mts @@ -0,0 +1 @@ +console.log('Hello, World!'); diff --git a/examples/rewrite/component/component.css b/examples/rewrite/component/component.css new file mode 100644 index 00000000..2ef60410 --- /dev/null +++ b/examples/rewrite/component/component.css @@ -0,0 +1,3 @@ +span { + color: red; +} diff --git a/examples/rewrite/component/component.prerender.tsx b/examples/rewrite/component/component.prerender.tsx new file mode 100644 index 00000000..f39a36a1 --- /dev/null +++ b/examples/rewrite/component/component.prerender.tsx @@ -0,0 +1,20 @@ +import { polyfillDeclarativeShadowDom } from '@rules_prerender/declarative_shadow_dom/preact.mjs'; +import { Template, includeScript, inlineStyle } from '@rules_prerender/preact'; +import { Transitive } from '../transitive/transitive.prerender.js'; +import { VNode } from 'preact'; + +export function Component({ name }: { name: string }): VNode { + return
+ + + +
; +} diff --git a/examples/rewrite/component/image.png b/examples/rewrite/component/image.png new file mode 100644 index 0000000000000000000000000000000000000000..7f2ecaaa7986a7cc2d7a81639e10c3ff1aaeea0f GIT binary patch literal 9948 zcmeHrc|6qJ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zQ^B;lQ`&I(f}NvJRdg|B;tF>y|gW`0KnOECvO5kYB~$PlN6@| z(!Kukz1KS~eJ2LK4Wbu?5>&D;7O_UV}#v23lO!ONRAuIim)`r@1tDT*iu{ghSQ(dRdJ~FL7dWUD(_fX9C{@S&^;e&dX!J z^!g?3&imhNTvF`sX$mI2ptPG_X`4jNY0WLMgA>B4jAzt+VAHN+(pDq{u)MI#E|nO) z%zRdXk`|yus(?x9Awlp55{Ql_Z-HJ9u}WV{JAVk7XIo+U-4hxCnZY@#%tx zbLoU<(qaMQmw3())}}WCx9FnxgAqs-y)6U1p_JiI=a`Co&r-h@bPb1h*4GtE6zxfu zYflk)i*zPZZfMk@`tZfiY3<7cz70Gw$0Q4z>pR({Qv`(47+TTqSEJX0OOCyK$h3%)$EPVUR->#&`2s# z67{5#(RJub)FHXC&m*rpBv%Eyo)ai;yx&9yBdKsB7JI3I$xUbjTX@QK%BuO4Rm#G5 zw>M;NI5(Fb0|25qHZEa=Vvt}CG9U1Af9A*4(rtTjxogW;T)3?z1M`M221 z4t6ZM`_2fCAqpOn9`+vED@|GZX)n)Cf4XyKJpK8K2&&W%Tw=(spl(GmR#{N)|KnWO eoonUAyUe=u5Zla^)-`;d19UX?HOkfOL;nkXh@33| literal 0 HcmV?d00001 diff --git a/examples/rewrite/site.prerender.tsx b/examples/rewrite/site.prerender.tsx new file mode 100644 index 00000000..169163a2 --- /dev/null +++ b/examples/rewrite/site.prerender.tsx @@ -0,0 +1,18 @@ +import { PrerenderResource, renderToHtml } from '@rules_prerender/preact'; +import { Component } from './component/component.prerender.js'; + +export default function* (): Generator { + yield PrerenderResource.fromHtml('/index.html', renderToHtml( + + + Rewrite + + + +

Rewrite

+ + + + + )); +} diff --git a/examples/rewrite/transitive/BUILD.bazel b/examples/rewrite/transitive/BUILD.bazel new file mode 100644 index 00000000..6a765a56 --- /dev/null +++ b/examples/rewrite/transitive/BUILD.bazel @@ -0,0 +1,14 @@ +load("//:index.bzl", prerender_component = "prerender_component2") +load("//tools/typescript:defs.bzl", "ts_project") + +prerender_component( + name = "transitive", + prerender = ":prerender", + visibility = ["//examples/rewrite:__subpackages__"], +) + +ts_project( + name = "prerender", + srcs = ["transitive.prerender.tsx"], + deps = ["//:node_modules/preact"], +) diff --git a/examples/rewrite/transitive/transitive.prerender.tsx b/examples/rewrite/transitive/transitive.prerender.tsx new file mode 100644 index 00000000..375205cb --- /dev/null +++ b/examples/rewrite/transitive/transitive.prerender.tsx @@ -0,0 +1,7 @@ +import { VNode } from 'preact'; + +export function Transitive({ name }: { name: string }): VNode { + return
+ Hello to {name} from transitive component! +
; +}