-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors external example to use a separate component.
Refs #48. Need to refactor the way that `tsconfig.json` was managed and also realized that I needed to have a separate `tsconfig.client.json` to make sure it was compiled targetting ESM.
- Loading branch information
Showing
10 changed files
with
100 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
load("@aspect_rules_ts//ts:defs.bzl", "ts_project") | ||
load( | ||
"@rules_prerender//:index.bzl", | ||
"css_library", | ||
"prerender_component", | ||
"web_resources", | ||
) | ||
|
||
prerender_component( | ||
name = "component", | ||
srcs = ["component.ts"], | ||
scripts = [":script"], | ||
styles = [":style"], | ||
resources = [":resources"], | ||
source_map = True, | ||
tsconfig = "//:tsconfig", | ||
visibility = ["//:__subpackages__"], | ||
lib_deps = ["//:node_modules/rules_prerender"], | ||
deps = ["//:prerender_components/@rules_prerender/declarative_shadow_dom"], | ||
) | ||
|
||
ts_project( | ||
name = "script", | ||
srcs = ["script.ts"], | ||
declaration = True, | ||
source_map = True, | ||
tsconfig = "//:tsconfig_client", | ||
) | ||
|
||
css_library( | ||
name = "style", | ||
srcs = ["style.css"], | ||
) | ||
|
||
web_resources( | ||
name = "resources", | ||
entries = { | ||
"/logo": "logo.png", | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { includeScript, inlineStyle } from 'rules_prerender'; | ||
import { polyfillDeclarativeShadowDom } from '@rules_prerender/declarative_shadow_dom'; | ||
|
||
export function renderComponent(): string { | ||
return ` | ||
<my-component> | ||
<template shadowroot="open"> | ||
<img src="/logo" /> | ||
<div>Component</div> | ||
<div id="replace">This text to be replaced by JavaScript.</div> | ||
${polyfillDeclarativeShadowDom()} | ||
${includeScript('component/script.js')} | ||
${inlineStyle('external/component/style.css')} | ||
</template> | ||
</my-component> | ||
`.trim(); | ||
} |
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class MyComponent extends HTMLElement { | ||
connectedCallback(): void { | ||
const el = this.shadowRoot.querySelector('#replace'); | ||
if (!el) throw new Error('Could not find `#replace` element.'); | ||
el.textContent = 'This text rendered by page JavaScript!'; | ||
} | ||
} | ||
|
||
customElements.define('my-component', MyComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
:host { | ||
display: block; | ||
} | ||
|
||
span { | ||
color: red; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
// Override module so `tsc` generates JS with ESM `import` instead of CommonJS `require()`. | ||
"module": "ES2020", | ||
} | ||
} |