From ebae5c96bcb43e03f3f435c12243eef79d33adc4 Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Fri, 10 Feb 2023 23:09:28 -0800 Subject: [PATCH] Adds script to external example. Refs #48. This mostly works just fine. I did notice that source maps seem to be broken, though that seems like a problem with the new `@aspect_rules_js` toolchain rather than this specific external example. I left a TODO to follow up with that separately. --- examples/external/BUILD.bazel | 10 ++++++++++ examples/external/script.ts | 1 + examples/external/site.ts | 3 ++- examples/external/tsconfig.json | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 examples/external/script.ts diff --git a/examples/external/BUILD.bazel b/examples/external/BUILD.bazel index 11c9e7d4..4f7af97c 100644 --- a/examples/external/BUILD.bazel +++ b/examples/external/BUILD.bazel @@ -1,5 +1,6 @@ load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_run_binary") load("@aspect_rules_js//npm:defs.bzl", "npm_link_package") +load("@aspect_rules_ts//ts:defs.bzl", "ts_project") load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@npm_user//:defs.bzl", "npm_link_all_packages") load("@rules_prerender//:index.bzl", "prerender_pages", "web_resources_devserver") @@ -15,10 +16,19 @@ npm_link_package( prerender_pages( name = "site", src = "site.ts", + scripts = [":script"], + source_map = True, # TODO(#48): This doesn't seem to work? tsconfig = "//:tsconfig.json", lib_deps = ["//:node_modules/rules_prerender"], ) +ts_project( + name = "script", + srcs = ["script.ts"], + declaration = True, + source_map = True, +) + web_resources_devserver( name = "devserver", resources = ":site", diff --git a/examples/external/script.ts b/examples/external/script.ts new file mode 100644 index 00000000..eb065f93 --- /dev/null +++ b/examples/external/script.ts @@ -0,0 +1 @@ +console.log('Hello, World!'); diff --git a/examples/external/site.ts b/examples/external/site.ts index afa68581..7e340d54 100644 --- a/examples/external/site.ts +++ b/examples/external/site.ts @@ -1,4 +1,4 @@ -import { PrerenderResource } from 'rules_prerender'; +import { includeScript, PrerenderResource } from 'rules_prerender'; export default function*(): Generator { yield PrerenderResource.of('/index.html', ` @@ -10,6 +10,7 @@ export default function*(): Generator {

Hello, World!

+ ${includeScript('script.js')} `.trim()); diff --git a/examples/external/tsconfig.json b/examples/external/tsconfig.json index 82e05044..18cec89a 100644 --- a/examples/external/tsconfig.json +++ b/examples/external/tsconfig.json @@ -4,6 +4,7 @@ "target": "ES2020", "module": "CommonJS", "declaration": true, + "sourceMap": true, "paths": { "rules_prerender": ["../../packages/rules_prerender"], },