deno.land / x / abc@v1.3.3 / examples / ultra_cat_app / jsx_loader.ts
1234567891011121314151617181920212223242526import { 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); };
Version Info