diff --git a/bun.lockb b/bun.lockb index 352c549..24398d9 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/index.html b/index.html index 739595a..3b8e86e 100644 --- a/index.html +++ b/index.html @@ -42,6 +42,6 @@
- + diff --git a/index.ts b/index.ts index ab070e0..8ec76ae 100644 --- a/index.ts +++ b/index.ts @@ -49,16 +49,6 @@ const api_endpoints: Handler[] = [ website_umami ]; -const builds = await Bun.build({ - entrypoints: ["./src/App.tsx", "index.css"], - target: "browser", - minify: { - identifiers: true, - syntax: true, - whitespace: true, - }, -}); - const servers: Server[] = ports.map((port) => Bun.serve({ idleTimeout: 30, // @ts-expect-error https://github.com/oven-sh/bun/issues/17772 @@ -70,7 +60,7 @@ const servers: Server[] = ports.map((port) => Bun.serve({ // merciless sanitization let pathname = url.pathname; pathname = pathname - .replace(/([^A-Za-z0-9/.-_])/g, "") + .replace(/([^A-Za-z0-9/._-])/g, "") .replace(/(? Bun.serve({ // MAIN PAGE if (pathname === "/") { - const indexContent = await Bun.file("index.html").text(); + const indexContent = await Bun.file("./dist/index.html").text(); return new Response(indexContent, {headers: {"Content-Type": "text/html"}}); } - if (pathname === "/App.tsx" && req.method === "GET") { - return new Response(builds.outputs[0].stream(), { - headers: { - "Content-Type": builds.outputs[0].type, - }, - }); - }; - - // EXTERNAL TO MAIN PAGE - if (pathname === "/index.css" && req.method === "GET") { - return new Response(builds.outputs[1].stream(), { - headers: { - "Content-Type": builds.outputs[1].type, - }, - }); - }; - + if (pathname.startsWith("/compressed")) { + const asset = Bun.file("./dist" + pathname); + return await asset.exists() ? new Response(asset, {status: 200}) : new Response("Not Found", {status: 404}); + } if (pathname.startsWith("/assets")) { const asset = Bun.file("." + pathname); diff --git a/package.json b/package.json index 0bf741d..201eb01 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "scripts": { - "dev": "bunx bun css && bun --hot index.ts --dev", - "css": "bun tailwindcss -i ./src/App.css -o index.css", - "lint": "bunx eslint .", - "start": "bun install && bunx bun css && bun run index.ts" + "dev": "bun css && vite build && bun --hot index.ts --dev", + "css": "tailwindcss -i ./src/App.css -o index.css", + "lint": "eslint .", + "getready": "bun install && bun css && vite build", + "start": "bun getready && bun run index.ts" }, "dependencies": { "@bachmacintosh/wanikani-api-types": "^1.7.0", @@ -18,24 +19,24 @@ }, "devDependencies": { "@eslint/eslintrc": "^3.3.0", - "@eslint/js": "^9.21.0", + "@eslint/js": "^9.22.0", "@stylistic/eslint-plugin": "^3.1.0", "@tailwindcss/forms": "^0.5.10", - "@tailwindcss/postcss": "^4.0.11", + "@tailwindcss/postcss": "^4.0.12", "@types/bun": "latest", - "@types/node": "^20.17.23", "@types/react": "^19.0.10", "@types/react-dom": "^19.0.4", - "autoprefixer": "^10.4.20", + "autoprefixer": "^10.4.21", "dotenv": "^16.4.7", - "eslint": "^9.21.0", + "eslint": "^9.22.0", "eslint-config-xo-typescript": "^7.0.0", "eslint-plugin-react": "^7.37.4", "postcss": "^8.5.3", "react-animate-height": "^3.2.3", "tailwindcss": "^3.4.17", "typescript": "^5.8.2", - "typescript-eslint": "^8.26.0" + "typescript-eslint": "^8.26.1", + "vite": "^6.2.1" }, "imports": { "#Main/*": "./src/Main/*", diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 0000000..9bcbc55 --- /dev/null +++ b/vite.config.js @@ -0,0 +1,13 @@ +export default { + build: { + outDir: "dist", + rollupOptions: { + output: { + inlineDynamicImports : true, + entryFileNames: `compressed/[name].js`, + chunkFileNames: `compressed/[name].js`, + assetFileNames: `compressed/[name].[ext]` + } + } + } +} \ No newline at end of file