Skip to content

Commit f4d397a

Browse files
committed
use vite for dev server
1 parent 593adae commit f4d397a

File tree

23 files changed

+109
-259
lines changed

23 files changed

+109
-259
lines changed

.env.example

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,13 @@
55
#########################################################################################################################################
66

77
# determines whether the app runs in development or production mode
8-
# the app will run in development mode unless either 'BUN_ENV' or 'NODE_ENV' is explicitly set to 'production'
8+
# the app will run in development mode unless either 'VITE_ENV' is explicitly set to 'production'
99
# default: development mode
10-
BUN_ENV=development
10+
VITE_ENV=development
1111

1212
# the port the elysia http server runs on (make sure to keep consistent with Dockerfile and fly.toml, if applicable)
1313
# default: 3000
14-
PORT=3000
14+
VITE_PORT=3000
1515

16-
# the port the socket.io websocket server runs on (make sure to keep consistent with Dockerfile and fly.toml, if applicable)
17-
# default: 3001
18-
WS_PORT=3001
19-
20-
# the host url of the app - MUST BE SET IN PRODUCTION to whitelist domain in socket.io server CORS config (i.e. https://my-prod-url.com)
21-
# default: http://localhost
22-
HOST=http://localhost
23-
24-
# the url of the discit-api server
25-
# default: http://localhost:5000
26-
API_URL==http://localhost:5000
16+
# must match the secret api key of the discit-api - used to authenticate privileged requests
17+
VITE_API_KEY=********

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v3
1616
- uses: superfly/flyctl-actions/setup-flyctl@master
17-
- run: flyctl deploy --remote-only --detach --no-cache --config fly.toml --build-secret API_KEY=${{ secrets.API_KEY }}
17+
- run: flyctl deploy --remote-only --detach --no-cache --config fly.toml --build-secret VITE_API_KEY=${{ secrets.VITE_API_KEY }}

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ COPY --link . .
1616
# install dependencies, lint project, build frontend, and compile backend
1717
RUN bun install --ignore-scripts --frozen-lockfile
1818
RUN bun run biome ci .
19-
RUN --mount=type=secret,id=API_KEY \
20-
API_KEY="$(cat /run/secrets/API_KEY)" bun run build:prod
19+
RUN --mount=type=secret,id=VITE_API_KEY \
20+
VITE_API_KEY="$(cat /run/secrets/VITE_API_KEY)" bun run build:prod
2121
RUN bun run compile
2222

2323
# minimalist final stage for app image

bun.lock

Lines changed: 8 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build": "bun run scripts/build.ts",
1515
"build:prod": "bun run scripts/build.ts BUN_ENV=production && workbox injectManifest workbox-config.json",
1616
"compile": "bun build --compile --minify --sourcemap src/server/index.ts --outfile main",
17-
"dev": "bun run --watch src/server/index.ts",
17+
"dev": "vite",
1818
"start": "bun run src/server/index.ts"
1919
},
2020
"devDependencies": {
@@ -39,10 +39,9 @@
3939
"react-hot-toast": "^2.5.2",
4040
"react-infinite-scroll-hook": "^5.0.2",
4141
"react-router-dom": "^7.5.2",
42-
"socket.io": "^4.8.1",
43-
"socket.io-client": "^4.8.1",
4442
"typescript": "^5.8.3",
4543
"vite": "^6.3.4",
44+
"vite-tsconfig-paths": "^5.1.4",
4645
"workbox-cli": "^7.3.0",
4746
"workbox-routing": "^7.3.0",
4847
"workbox-strategies": "^7.3.0"

processes/buildClient.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

processes/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

processes/watch.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/build.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
1-
import { buildClient } from "@processes";
1+
import { $ } from "bun";
2+
import { copyPlugin } from "bun-copy-plugin";
3+
4+
import { Env, Path } from "@constants";
5+
import { Config, log, now, parseArg } from "@helpers";
6+
7+
const start = now();
8+
9+
const isProd = Config.IS_PROD || (parseArg("BUN_ENV") ?? parseArg("NODE_ENV")) === Env.Production;
10+
11+
const src = Path.ClientSrc;
12+
const outdir = Path.Public;
13+
14+
const toCopy = ["icons/", "favicon.ico", "manifest.json"];
15+
16+
await $`rm -rf ${outdir}`;
17+
18+
await Bun.build({
19+
entrypoints: [`${src}/index.html`, `${src}/sw.ts`],
20+
outdir,
21+
define: {
22+
"import.meta.env.VITE_ENV": `"${isProd ? Env.Production : Env.Development}"`,
23+
"import.meta.env.VITE_API_KEY": `"${Config.API_KEY}"`
24+
},
25+
sourcemap: isProd ? "none" : "linked",
26+
naming: {
27+
entry: "[dir]/[name].[ext]",
28+
asset: "[dir]/[name]~[hash].[ext]",
29+
chunk: "[dir]/chunk~[hash].[ext]"
30+
},
31+
plugins: toCopy.map(path => copyPlugin(`${src}/${path}`, `${outdir}/${path}`)),
32+
minify: isProd
33+
});
34+
35+
const buildMode = isProd ? Env.Production : Env.Development;
36+
const buildTime = (now() - start).toFixed(2);
37+
38+
log.info(`Build completed in ${buildMode} mode in ${buildTime}ms`);
239

3-
await buildClient();
440
process.exit(0);

src/client/assets/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-ignore
21
import discitSvg from "./discit.svg";
32

43
export { discitSvg };

0 commit comments

Comments
 (0)