Skip to content

Commit

Permalink
fix (web): HTML not TS as entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Jan 17, 2025
1 parent 115130a commit 8f7c8f3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion java/dev/enola/web/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public UI(EnolaServiceBlockingStub service, ThingMetadataProvider metadataProvid
public void register(WebHandlers handlers) {
// TODO Hard-coding this here like that is non-sense of course... will be fixed later!
// BTW It's ./public/ instead of ./web/public/ only because web/README.md assumes `cd web`.
var fixMeToNotBeHardCoded = new File("./public/");
var fixMeToNotBeHardCoded = new File("./web-out/");
handlers.register("/wui/", new StaticWebHandler("/wui/", fixMeToNotBeHardCoded));
handlers.register("/ui/static/", new StaticWebHandler("/ui/static/", "static"));
handlers.register("/ui", this);
Expand Down
5 changes: 4 additions & 1 deletion web/ToDo.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

## Tech

1. Try https://bun.sh/docs/bundler/html
1. Apply https://bun.sh/docs/typescript#suggested-compileroptions
1. Fix `bun tsc`
1. Adopt https://bun.sh/docs/bundler/fullstack ... and fix CORS!
1. Either rename web-out/index*.html to `index.html` in `build.ts`,
OR make `../enola server` send either (better) `Cache-Control: no-cache` & `ETag: "abcdef1234"`
(or just `Cache-Control: no-store`; or `max-age=0`, really same?)

## Functional

Expand Down
2 changes: 1 addition & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
</div>
</div>
<div id="container" style="width: 100%; height: 600px; background: white"></div>
<script src="bundles/index.js" type="module"></script>
<script src="../src/browser/index.ts" type="module"></script>
</body>
</html>
21 changes: 13 additions & 8 deletions web/src/bun/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

import { build } from "bun"

// TODO Run both tsc & test from here, e.g. by using `concurrently` or `npm-run-all` (README.md)
// TODO Adopt https://bun.sh/docs/bundler/fullstack

// TODO Support watch mode, ideally like https://esbuild.github.io/api/#live-reload
// TODO Run both tsc & test from here, e.g. by using `concurrently` or `npm-run-all` (README.md)

const result = await build({
entrypoints: ["src/browser/index.ts"],
outdir: "public/bundles/",
html: true,
experimentalCss: true,

entrypoints: ["public/index.html"],
outdir: "web-out/",

minify: true,
sourcemap: "linked",

// TODO naming: "./[dir]/[name]-[hash].[ext]" BUT then how to reference it in the HTML?!
naming: "./[dir]/[name]-[hash].[ext]",

throw: true,
})

if (!result.success) {
if (result.success) {
// result.outputs.map(output => console.log("✅", output.path))
console.log("✅ Successfully 📦 bundled!")
process.exit(0)
} else {
console.error("Build failed:", result.logs)
process.exit(1)
}

// TODO How to bundle CSS as well?

0 comments on commit 8f7c8f3

Please sign in to comment.