Skip to content

Commit f098807

Browse files
committed
Updates inlineStyle() to use relative imports with import.meta.
Refs #69. This brings `inlineStyle()` into parity with `includeScript()`. Input strings are relative to the file they are imported from. I had to update the CSS import map to drop the workspace name in order to use `wkspRelative()` as is. I think this is ok for now as we don't really have a story for inlining styles from different workspace. Most likely this would be done by using bare imports and inlining files from NPM packages, rather than external workspaces.
1 parent 3f26560 commit f098807

21 files changed

Lines changed: 187 additions & 67 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function renderMyComponent(name: string): string {
154154
${includeScript('./my_component.mjs', import.meta)}
155155
156156
<!-- Inline the associated CSS styles, scoped to this shadow root. -->
157-
${inlineStyle('my_workspace/my_component/my_component.css')}
157+
${inlineStyle('./my_component.css', import.meta)}
158158
</template>
159159
160160
<!-- Other components are placed in light DOM and visible at the \`<slot />\`. -->

examples/declarative_shadow_dom/component.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function renderComponent(lightDom: string): Promise<string> {
1313
${polyfillDeclarativeShadowDom()}
1414
1515
<!-- Inline styles to apply them within this shadow root. -->
16-
${inlineStyle('rules_prerender/examples/declarative_shadow_dom/component.css')}
16+
${inlineStyle('./component.css', import.meta)}
1717
1818
<!-- Shadow DOM content, styled with the associated style
1919
sheet. -->

examples/external/component/component.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function renderComponent(): string {
1111
1212
${polyfillDeclarativeShadowDom()}
1313
${includeScript('./script.mjs', import.meta)}
14-
${inlineStyle('external/component/style.css')}
14+
${inlineStyle('./style.css', import.meta)}
1515
</template>
1616
</my-component>
1717
`.trim();

examples/multi_page/pages.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function generate(content: string): string {
2929
<meta charset="utf-8">
3030
3131
${includeScript('./script.mjs', import.meta)}
32-
${inlineStyle('rules_prerender/examples/multi_page/styles.css')}
32+
${inlineStyle('./styles.css', import.meta)}
3333
</head>
3434
<body>
3535
${content}

examples/site/about/about.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default async function*():
5757
dignissim quis, venenatis non mi. Curabitur lacinia tincidunt vulputate.
5858
Proin non vehicula risus, id pharetra lorem.</p>
5959
60-
${inlineStyle('rules_prerender/examples/site/about/about.css')}
60+
${inlineStyle('./about.css', import.meta)}
6161
</template>
6262
</article>
6363
`),

examples/site/components/base/base.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function baseLayout(
2020
<head>
2121
<title>${title}</title>
2222
<meta charset="utf-8">
23-
${inlineStyle('rules_prerender/examples/site/components/base/base.css')}
23+
${inlineStyle('./base.css', import.meta)}
2424
</head>
2525
<body>
2626
${renderHeader()}

examples/site/components/footer/footer.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function renderFooter(): string {
1111
<a href="https://bazel.build/" rel="noopener" target="_blank">Bazel</a> and
1212
<a href="${repo}" rel="noopener" target="_blank">rules_prerender</a>.
1313
</div>
14-
${inlineStyle('rules_prerender/examples/site/components/footer/footer.css')}
14+
${inlineStyle('./footer.css', import.meta)}
1515
</template>
1616
</footer>
1717
`.trim();

examples/site/components/header/header.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function renderHeader(): string {
1515
</ul>
1616
</nav>
1717
18-
${inlineStyle('rules_prerender/examples/site/components/header/header.css')}
18+
${inlineStyle('./header.css', import.meta)}
1919
</template>
2020
</header>
2121
`.trim();

examples/styles/page.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function* (): Generator<PrerenderResource, void, void> {
1212
<div id="shadowroot">
1313
<template shadowroot="open">
1414
<div id="hello">Hello, World!</div>
15-
${inlineStyle('rules_prerender/examples/styles/styles.css')}
15+
${inlineStyle('./styles.css', import.meta)}
1616
</template>
1717
</div>
1818
<div id="goodbye">Goodbye, World!</div>

examples/testonly/component/component.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function renderComponent(): string {
1010
<slot></slot>
1111
1212
${includeScript('./component_script.mjs', import.meta)}
13-
${inlineStyle('rules_prerender/examples/testonly/component/component_styles.css')}
13+
${inlineStyle('./component_styles.css', import.meta)}
1414
</template>
1515
${renderTransitive()}
1616
</div>

0 commit comments

Comments
 (0)