Skip to content

Commit 1138894

Browse files
committed
[frontend]: switch to vite-plugin-static-copy for scramjet files and setup controller
1 parent 7e85a10 commit 1138894

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

frontend/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Vite + TS</title>
8+
9+
<script src="/scram/scramjet.controller.js"></script>
810
</head>
911

1012
<body>

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"dependencies": {
1616
"@iconify/types": "^2.0.0",
1717
"@ktibow/iconset-material-symbols": "^0.0.1749705809",
18+
"@mercuryworkshop/epoxy-transport": "^2.1.27",
19+
"@mercuryworkshop/scramjet": "workspace:scramjet",
1820
"dreamland": "workspace:dreamland",
19-
"@mercuryworkshop/scramjet": "workspace:scramjet"
21+
"vite-plugin-static-copy": "^3.1.0"
2022
}
2123
}

frontend/public/sw.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
importScripts("/scram/scramjet.shared.js", "/scram/scramjet.worker.js");
2+
3+
const scramjet = new ScramjetServiceWorker();
4+
5+
async function handleRequest(event) {
6+
await scramjet.loadConfig();
7+
if (scramjet.route(event)) {
8+
return scramjet.fetch(event);
9+
}
10+
11+
return fetch(event.request);
12+
}
13+
14+
self.addEventListener("fetch", (event) => {
15+
event.respondWith(handleRequest(event));
16+
});

frontend/src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const scramjet = new ScramjetController({
3333

3434
scramjet.init();
3535
navigator.serviceWorker.register("./sw.js");
36+
let frame = scramjet.createFrame();
3637

3738
let browser = createBrowser();
3839
(self as any).browser = browser;

frontend/vite.config.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
import { defineConfig } from "vite";
22
import { epoxyPath } from "@mercuryworkshop/epoxy-transport";
3+
import { scramjetPath } from "@mercuryworkshop/scramjet";
34
import { baremuxPath } from "@mercuryworkshop/bare-mux/node";
5+
6+
import { viteStaticCopy } from "vite-plugin-static-copy";
47
console.log(epoxyPath, baremuxPath);
58

69
export default defineConfig({
710
plugins: [
8-
{
9-
name: "static-files",
10-
configureServer(server) {
11-
server.middlewares.use((req, res, next) => {
12-
if (req.url.startsWith("/epoxy/")) {
13-
req.url = req.url.replace("/epoxy/", epoxyPath + "/");
14-
} else if (req.url.startsWith("/baremux/")) {
15-
req.url = req.url.replace("/baremux/", baremuxPath + "/");
16-
}
17-
next();
18-
});
19-
},
20-
},
11+
viteStaticCopy({
12+
structured: false,
13+
targets: [
14+
{
15+
src: epoxyPath + "/*",
16+
dest: "epoxy/",
17+
},
18+
{
19+
src: baremuxPath + "/*",
20+
dest: "baremux/",
21+
},
22+
{
23+
src: scramjetPath + "/*",
24+
dest: "scram/",
25+
},
26+
],
27+
}),
2128
],
2229
});

0 commit comments

Comments
 (0)