diff --git a/deno.json b/deno.json index 9a94b43..1f5fffd 100644 --- a/deno.json +++ b/deno.json @@ -6,6 +6,7 @@ "imports": { "react":"https://esm.sh/preact@10.15.1/compat", + "react-original":"https://esm.sh/preact@10.15.1/compat", "app": "./app.tsx" } } \ No newline at end of file diff --git a/example/app.tsx b/example/app.tsx index ed9b503..03c2ce0 100644 --- a/example/app.tsx +++ b/example/app.tsx @@ -1,5 +1,4 @@ - - +import React from "react"; export default ()=> { return

hey!

diff --git a/local.tsx b/local.tsx index e29ed2f..ced1167 100644 --- a/local.tsx +++ b/local.tsx @@ -29,10 +29,33 @@ Configure({ inImports[key] = value.substring(1); } }); + + inImports["react-original"] = inImports["react"]; + inImports["react"] = "/_lib_/react.tsx"; + console.log(inImports); return inImports; }, - Serve(inReq, inURL, inExt, inMap) + async Serve(inReq, inURL, inExt, inMap) { + if(Transpile.Check(inExt) && !inURL.searchParams.get("reload") && !inURL.pathname.startsWith("/_lib_/")) + { + const imp = await import(Directory+inURL.pathname); + const members = []; + for( const key in imp ) { members.push(key); } + return new Response(`import {FileListen} from "/_lib_/hmr.tsx"; + import * as Import from "${inURL.pathname}?reload=0"; + ${ members.map(m=>`let proxy_${m} = Import.${m}; + export { proxy_${m} as ${m} }; + `).join(" ") } + const reloadHandler = (updatedModule)=> + { + ${ members.map(m=>`proxy_${m} = updatedModule.${m};`).join("\n") } + }; + FileListen("${inURL.pathname}", reloadHandler);`, {headers:{"content-type":"application/javascript"}} + ); + } + + if(inReq.headers.get("upgrade") == "websocket") { try diff --git a/serve.tsx b/serve.tsx index 53fa90d..b50d80b 100644 --- a/serve.tsx +++ b/serve.tsx @@ -64,7 +64,8 @@ let Configuration:Configuration = `, {status:200, headers:{"content-type":"text/html"}}); @@ -165,16 +166,6 @@ HTTP.serve(async(req: Request)=> return custom; } - // custom page html - if(!ext) - { - const shell = await Configuration.Shell(req, url, ext, ImportMap); - if(shell) - { - return shell; - } - } - // transpileable files if(Transpile.Check(ext)) { @@ -194,6 +185,16 @@ HTTP.serve(async(req: Request)=> } } + // custom page html + if(!ext) + { + const shell = await Configuration.Shell(req, url, ext, ImportMap); + if(shell) + { + return shell; + } + } + // all other static files if(ext) {