diff options
author | 2021-08-09 02:21:31 -0700 | |
---|---|---|
committer | 2021-08-09 02:21:31 -0700 | |
commit | f74771144e71e77969fe50d250818e2fcc0800bd (patch) | |
tree | 85b18e33fc8a7d5c8a8438d8af23439cef74b949 /examples/nexty/framework.server.development.tsx | |
parent | 687b22908f15020d254eb90672bcdddbdaad7f06 (diff) | |
download | bun-f74771144e71e77969fe50d250818e2fcc0800bd.tar.gz bun-f74771144e71e77969fe50d250818e2fcc0800bd.tar.zst bun-f74771144e71e77969fe50d250818e2fcc0800bd.zip |
Split up + generate client & server bundles, support framework +router in GenerateNodeModulesBundle , read framework from package.json + rename "publicURL" to "origin" + add import.meta.filepath
Former-commit-id: 1e76ebb5375247231181ec19a6396c6acf4684fb
Diffstat (limited to 'examples/nexty/framework.server.development.tsx')
-rw-r--r-- | examples/nexty/framework.server.development.tsx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/nexty/framework.server.development.tsx b/examples/nexty/framework.server.development.tsx new file mode 100644 index 000000000..0e28dac65 --- /dev/null +++ b/examples/nexty/framework.server.development.tsx @@ -0,0 +1,46 @@ +import ReactDOMServer from "react-dom/server.browser"; + +addEventListener("fetch", async (event: FetchEvent) => { + var route = Wundle.match(event); + + console.log("Main:", Wundle.main); + console.log("cwd:", Wundle.cwd); + console.log("Origin:", Wundle.origin); + + const { default: PageComponent } = await import(route.filePath); + // This returns all .css files that were imported in the line above. + // It's recursive, so any file that imports a CSS file will be included. + const stylesheets = Wundle.getImportedStyles() as string[]; + + const response = new Response(` + <!DOCTYPE html> +<html> + <head> + ${stylesheets + .map((style) => `<link rel="stylesheet" href="${style}">`) + .join("\n")} + + <link + rel="stylesheet" + crossorigin="anonymous" + href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;700&family=Space+Mono:wght@400;700" + /> + </head> + <body> + + <div id="reactroot">${ReactDOMServer.renderToString( + <PageComponent /> + )}</div> + + <script src="${route.scriptSrc}" async type="module"></script> + </body> +</html> + `); + + event.respondWith(response); +}); + +// typescript isolated modules +export {}; + +declare var Wundle: any; |