boot-function #1

Merged
SethTrowbridge merged 25 commits from boot-function into master 2023-06-21 07:53:14 -04:00
4 changed files with 38 additions and 14 deletions
Showing only changes of commit 0e6a3d3efb - Show all commits

View File

@ -6,6 +6,7 @@
"imports": "imports":
{ {
"react":"https://esm.sh/preact@10.15.1/compat", "react":"https://esm.sh/preact@10.15.1/compat",
"react-original":"https://esm.sh/preact@10.15.1/compat",
"app": "./app.tsx" "app": "./app.tsx"
} }
} }

View File

@ -1,5 +1,4 @@
import React from "react";
export default ()=> export default ()=>
{ {
return <div><h1>hey!</h1></div> return <div><h1>hey!</h1></div>

View File

@ -29,10 +29,33 @@ Configure({
inImports[key] = value.substring(1); inImports[key] = value.substring(1);
} }
}); });
inImports["react-original"] = inImports["react"];
inImports["react"] = "/_lib_/react.tsx";
console.log(inImports);
return 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") if(inReq.headers.get("upgrade") == "websocket")
{ {
try try

View File

@ -64,7 +64,8 @@ let Configuration:Configuration =
<script type="module"> <script type="module">
import App from "app"; import App from "app";
import React from "react"; 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> </script>
</body> </body>
</html>`, {status:200, headers:{"content-type":"text/html"}}); </html>`, {status:200, headers:{"content-type":"text/html"}});
@ -165,16 +166,6 @@ HTTP.serve(async(req: Request)=>
return custom; return custom;
} }
// custom page html
if(!ext)
{
const shell = await Configuration.Shell(req, url, ext, ImportMap);
if(shell)
{
return shell;
}
}
// transpileable files // transpileable files
if(Transpile.Check(ext)) 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 // all other static files
if(ext) if(ext)
{ {