Skip to content

Commit 76a3ac5

Browse files
committed
website: serve non-production (minified) treehouse library bundle in dev
1 parent 1cd835b commit 76a3ac5

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/website/out
2+
/website/static/lib/treehouse.js

website/serve.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ await serve(async (req) => {
2020
const res = middleware(req);
2121
if (res) return res;
2222

23-
const pathname = new URL(req.url).pathname;
24-
25-
if (pathname === "/lib/treehouse.min.js" && lastBuild < Date.now()-1000) {
26-
await esbuild.build({
27-
entryPoints: ["lib/mod.ts"],
28-
bundle: true,
29-
outfile: "website/static/lib/treehouse.min.js",
30-
jsxFactory: "m",
31-
format: "esm",
32-
// minify: true,
33-
});
34-
lastBuild = Date.now();
23+
let pathname = new URL(req.url).pathname;
24+
25+
if (pathname === "/lib/treehouse.min.js") {
26+
if (lastBuild < Date.now()-1000) {
27+
await esbuild.build({
28+
entryPoints: ["lib/mod.ts"],
29+
bundle: true,
30+
outfile: "website/static/lib/treehouse.js",
31+
jsxFactory: "m",
32+
format: "esm",
33+
});
34+
lastBuild = Date.now();
35+
}
36+
Object.defineProperty(req, "url", {value: req.url.replace(".min", "")});
3537
}
3638

3739
if (pathname !== "/" && exists(`${rootdir}/static${pathname}`)) {

0 commit comments

Comments
 (0)