server updates
This commit is contained in:
parent
0cc2d914e1
commit
a0ec91940c
8
app.tsx
8
app.tsx
@ -1,2 +1,10 @@
|
||||
import * as React from "react"
|
||||
const dyn = await import("./app-dynamic.tsx");
|
||||
console.log(dyn);
|
||||
|
||||
|
||||
import Other from "./other.tsx";
|
||||
|
||||
console.log(Other);
|
||||
|
||||
React.render(<h1>sup!</h1>, document.querySelector("#app")||document.body);
|
@ -9,6 +9,10 @@
|
||||
"entry": "./app.tsx",
|
||||
"config": "./deno.json"
|
||||
},
|
||||
"tasks": {
|
||||
"go": "deno run -A bundler-inc.tsx",
|
||||
"serve": "deno run -A serve.tsx"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react"
|
||||
|
@ -4,5 +4,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body><script src="dump.js" type="module"></script>
|
||||
</body>
|
||||
<script src="/app.tsx" type="module"></script>
|
||||
</html>
|
||||
|
7
mod.ts
7
mod.ts
@ -29,6 +29,8 @@ const resolvePlugin:ESBuild.Plugin = {
|
||||
},
|
||||
};
|
||||
|
||||
await ESBuild.initialize({ worker: false });
|
||||
|
||||
export type ImportMap = Parameters<typeof Mapper.importmapPlugin>[0];
|
||||
export type BuildOptions = ESBuild.BuildOptions;
|
||||
export default async function(buildOptions={} as BuildOptions, importMap:ImportMap|false = false)
|
||||
@ -55,10 +57,9 @@ export default async function(buildOptions={} as BuildOptions, importMap:ImportM
|
||||
...buildOptions.plugins||[]
|
||||
]
|
||||
};
|
||||
await ESBuild.initialize({ worker: false });
|
||||
|
||||
const result = await ESBuild.build(configuration);
|
||||
ESBuild.stop();
|
||||
//ESBuild.stop();
|
||||
return result;
|
||||
}
|
||||
|
||||
export { ESBuild };
|
@ -1,3 +1,3 @@
|
||||
//import React from "react";
|
||||
//console.log(React.createElement("div", {}, "hey"));
|
||||
import React from "react";
|
||||
console.log(React.createElement("div", {}, "hey"));
|
||||
export default "TEST STRING";
|
47
serve.tsx
47
serve.tsx
@ -1,38 +1,55 @@
|
||||
import bundler from "./mod.ts";
|
||||
import {Root} from "./introspect.ts"
|
||||
|
||||
const transpiled:Map<string, string> = new Map();
|
||||
|
||||
const ServeJS =(inText:string)=> new Response(inText, {headers:{"content-type":"application/javascript"}});
|
||||
|
||||
const htmlFile = Deno.readTextFileSync(Deno.cwd()+"/index.html");
|
||||
|
||||
Deno.serve(async(req)=>{
|
||||
const url = new URL(req.url);
|
||||
const index = url.pathname.lastIndexOf(".");
|
||||
if(index > -1)
|
||||
{
|
||||
const ext = url.pathname.substring(index+1, index+3);
|
||||
|
||||
console.log(ext);
|
||||
console.log(url.pathname);
|
||||
|
||||
if(ext === "ts")
|
||||
const ext = url.pathname.substring(index+1);
|
||||
if(ext === "ts" || ext == "tsx" || ext == "js" || ext == "jsx")
|
||||
{
|
||||
if(ext == "js")
|
||||
{
|
||||
const lookup = transpiled.get(url.pathname);
|
||||
if(lookup)
|
||||
{
|
||||
return ServeJS(lookup);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const lookup = transpiled.get(url.pathname.substring(0, index)+".js");
|
||||
if(lookup)
|
||||
{
|
||||
return ServeJS(lookup);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
const results = await bundler({
|
||||
entryPoints:["."+url.pathname],
|
||||
outfile:"bundle.js",
|
||||
outdir:"/",
|
||||
entryNames: `[dir][name]`,
|
||||
splitting: true
|
||||
});
|
||||
results.outputFiles?.forEach(output=>{
|
||||
transpiled.set(output.path, output.text);
|
||||
})
|
||||
return new Response(`
|
||||
path: ${results.outputFiles[0].path}
|
||||
hash: ${results.outputFiles[0].hash}
|
||||
`, {headers:{"content-type":"application/javascript"}});
|
||||
return ServeJS(results.outputFiles[0].text);
|
||||
}
|
||||
|
||||
if(ext == "js")
|
||||
catch(e)
|
||||
{
|
||||
return new Response(transpiled.get(url.pathname)||"---", {headers:{"content-type":"application/javascript"}});
|
||||
return new Response("404", {status:404});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return new Response(url.pathname);
|
||||
return new Response(htmlFile, {headers:{"content-type": "text/html"}});
|
||||
});
|
Loading…
Reference in New Issue
Block a user