-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
40 lines (35 loc) · 1.05 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { serve } from "std/http/server.ts";
import { build, initialize } from "esbuild";
import { denoPlugins } from "esbuild-deno-loader";
import handler, { HandlerCache } from "./handler.ts";
import * as Responses from "./Responses.ts";
await initialize({ worker: false });
const cache: HandlerCache = {
async match(_, { entryPoint }) {
const { outputFiles: [{ contents }] = [] } = await build({
entryPoints: [entryPoint],
bundle: true,
minify: true,
format: "esm",
write: false,
external: [
"react",
"react-dom",
"react-dom/client",
"react-dom/server",
"https://esm.sh/[email protected]",
"https://esm.sh/[email protected]/client",
"https://esm.sh/[email protected]/server",
"esm.sh/*",
],
plugins: [
...denoPlugins({
importMapURL: new URL("./importMap.json", import.meta.url).href,
loader: "portable",
}),
],
});
return Responses.javascript(contents);
},
};
serve((request) => handler(request, { cache }));