deno.land / x / abc@v1.3.3 / examples / ultra_cat_app / jsx_loader.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
import { decode, Header, MiddlewareFunc, MIME } from "./deps.ts";const { transpileOnly, readFile } = Deno;
export const jsxLoader: MiddlewareFunc = (next) => async (c) => { const filepath = c.get("realpath") as string | undefined;
if (filepath && /\.[j|t]sx?$/.test(filepath)) { c.response.headers.set( Header.ContentType, MIME.ApplicationJavaScriptCharsetUTF8, ); const f = await readFile(filepath); return ( await transpileOnly( { [filepath]: decode(f), }, { jsx: "react" }, ) )[filepath].source; }
return next(c); };
abc

Version Info

Tagged at
4 years ago