add dev server (bun run dev → http://localhost:3000)
This commit is contained in:
@@ -7,15 +7,14 @@ Built with TypeScript and Canvas 2D, bundled with **Bun**.
|
||||
|
||||
```bash
|
||||
bun install # install deps (none currently required)
|
||||
bun start # build + prepare dist/
|
||||
bun start # production build → dist/
|
||||
open dist/index.html
|
||||
```
|
||||
|
||||
Or for development with watch mode:
|
||||
Or for development with live reload:
|
||||
|
||||
```bash
|
||||
bun run dev # watches src/ and rebuilds dist/main.js
|
||||
# then open dist/index.html manually
|
||||
bun run dev # starts dev server at http://localhost:3000 + watch mode
|
||||
```
|
||||
|
||||
## Controls
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { spawn } from "bun";
|
||||
|
||||
// Ensure dist/ has the HTML shell
|
||||
await Bun.write(
|
||||
"./dist/index.html",
|
||||
`<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Dungeon Crawl — Ranged / Melee</title>
|
||||
<style>
|
||||
*{margin:0;padding:0;box-sizing:border-box}
|
||||
body{background:#0a0a0a;display:flex;justify-content:center;align-items:center;height:100vh;font-family:monospace;overflow:hidden;user-select:none}
|
||||
canvas{display:block;border:1px solid #222;border-radius:2px;cursor:none}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="game" width="880" height="660"></canvas>
|
||||
<script src="main.js"></script>
|
||||
</body>
|
||||
</html>`
|
||||
);
|
||||
|
||||
// Start build watcher
|
||||
const builder = spawn(["bun", "build", "src/main.ts", "--outdir", "dist", "--target", "browser", "--watch"], {
|
||||
stdout: "inherit",
|
||||
stderr: "inherit",
|
||||
});
|
||||
|
||||
// Start dev server
|
||||
const port = 3000;
|
||||
const server = Bun.serve({
|
||||
port,
|
||||
async fetch(req) {
|
||||
const url = new URL(req.url);
|
||||
let path = url.pathname === "/" ? "/index.html" : url.pathname;
|
||||
const file = Bun.file("./dist" + path);
|
||||
return new Response(file);
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`\n Dev server: http://localhost:${port}`);
|
||||
console.log(` Watching: src/\n`);
|
||||
|
||||
// Graceful shutdown
|
||||
process.on("SIGINT", () => {
|
||||
builder.kill();
|
||||
server.stop();
|
||||
process.exit(0);
|
||||
});
|
||||
Vendored
+1090
-2
File diff suppressed because one or more lines are too long
+1
-2
@@ -4,9 +4,8 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "bun build src/main.ts --outdir dist --target browser --watch",
|
||||
"dev": "bun run dev.ts",
|
||||
"build": "bun run build.ts",
|
||||
"serve": "bun build src/main.ts --outdir dist --target browser && cp src/index.html dist/",
|
||||
"start": "bun run build && echo 'open dist/index.html'"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user