hmr roughed in
(you have to clear-cache?)
This commit is contained in:
parent
6b8a207809
commit
0e6a3d3efb
@ -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"
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
import React from "react";
|
||||
export default ()=>
|
||||
{
|
||||
return <div><h1>hey!</h1></div>
|
||||
|
25
local.tsx
25
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
|
||||
|
23
serve.tsx
23
serve.tsx
@ -64,7 +64,8 @@ let Configuration:Configuration =
|
||||
<script type="module">
|
||||
import App from "app";
|
||||
import React from "react";
|
||||
React.render(React.createElement(App), document.querySelector("#app"))
|
||||
const Wrapper =(props)=> React.createElement(App);
|
||||
React.render(React.createElement(Wrapper), document.querySelector("#app"))
|
||||
</script>
|
||||
</body>
|
||||
</html>`, {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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user