Skip to content

Commit

Permalink
Migrates examples/tsconfig/ to use Preact.
Browse files Browse the repository at this point in the history
Refs #71.
  • Loading branch information
dgp1130 committed Mar 13, 2023
1 parent 7cc8865 commit a00a438
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
15 changes: 13 additions & 2 deletions examples/tsconfig/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("//:index.bzl", "prerender_pages", "web_resources_devserver")

copy_to_bin(
name = "package",
srcs = ["package.json"],
)

prerender_pages(
name = "site",
src = "site.mts",
src = "site.tsx",
tsconfig = "tsconfig.json",
source_map = True,
bundle_js = False, # Optimization: No client-side JavaScript on this site.
lib_deps = ["//:node_modules/rules_prerender"],
# Need `"type": "module"` to load `*.js` files output by `*.tsx` compilation.
data = [":package"],
lib_deps = [
"//:node_modules/@rules_prerender/preact",
"//:node_modules/preact",
],
)

web_resources_devserver(
Expand Down
3 changes: 3 additions & 0 deletions examples/tsconfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
11 changes: 5 additions & 6 deletions examples/tsconfig/site.mts → examples/tsconfig/site.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrerenderResource } from 'rules_prerender';
import { PrerenderResource, renderToHtml } from '@rules_prerender/preact';

/**
* Renders HTML page.
Expand All @@ -7,17 +7,16 @@ import { PrerenderResource } from 'rules_prerender';
* tsconfig file used to compile this file.
*/
export default function*(foo): Generator<PrerenderResource, void, void> {
yield PrerenderResource.of('/index.html', `
<!DOCTYPE html>
yield PrerenderResource.of('/index.html', renderToHtml(
<html>
<head>
<title>tsconfig</title>
<meta charset="utf8">
<meta charSet='utf8' />
</head>
<body>
<h2>tsconfig</h2>
<span>${foo}</span>
<span>{foo}</span>
</body>
</html>
`);
));
}
9 changes: 6 additions & 3 deletions examples/tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
"paths": { /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// Set up absolute imports per: https://bazelbuild.github.io/rules_nodejs/TypeScript.html#ts_project
"rules_prerender": ["../../packages/rules_prerender"], // Map `rules_prerender` module to its implementation.
"rules_prerender/*": ["*"] // Map workspace-relative imports.
"rules_prerender": ["../../packages/rules_prerender"],
"@rules_prerender/*": ["../../packages/*"]
},
"moduleResolution": "node",
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */

/* JSX Options */
"jsx": "react-jsx", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"jsxImportSource": "preact",

/* Advanced Options */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
Expand Down

0 comments on commit a00a438

Please sign in to comment.