vite-elysia-forge 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -54
- package/dist/cli.d.ts +21 -22
- package/dist/cli.js +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ bun install vite-elysia-forge
|
|
|
18
18
|
|
|
19
19
|
### 2.1 Create Your API Handler
|
|
20
20
|
|
|
21
|
-
Place your Elysia handler at `
|
|
21
|
+
Place your Elysia handler at `server/api.ts` (default path):
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
24
|
import { Elysia } from "elysia";
|
|
@@ -43,7 +43,7 @@ import elysiaPlugin from "vite-elysia-forge";
|
|
|
43
43
|
export default defineConfig({
|
|
44
44
|
plugins: [
|
|
45
45
|
elysiaPlugin({
|
|
46
|
-
serverFile: "./
|
|
46
|
+
serverFile: "./server/api.ts",
|
|
47
47
|
}),
|
|
48
48
|
],
|
|
49
49
|
});
|
|
@@ -126,7 +126,7 @@ To enable WebSocket support, set `ws: true`:
|
|
|
126
126
|
|
|
127
127
|
```ts
|
|
128
128
|
elysiaPlugin({
|
|
129
|
-
serverFile: "./
|
|
129
|
+
serverFile: "./server/api.ts",
|
|
130
130
|
ws: true, // Enable WebSocket support
|
|
131
131
|
backendPort: 3001, // API runs on this port (default: 3001)
|
|
132
132
|
});
|
|
@@ -176,27 +176,18 @@ const app = new Elysia().use(
|
|
|
176
176
|
|
|
177
177
|
## 7. Production Deployment
|
|
178
178
|
|
|
179
|
-
The CLI provides build
|
|
179
|
+
The CLI provides a `build` command for building your Elysia API server. Frontend assets should be built separately using Vite's standard build process (`vite build`).
|
|
180
180
|
|
|
181
|
-
By default, the CLI looks for your API at `
|
|
181
|
+
By default, the CLI looks for your API at `server/api.ts`. You can specify a custom path with the `--entry` flag.
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
vite-elysia-forge build-static
|
|
185
|
-
vite-elysia-forge build-server --api server/api.ts
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
### 7.1 Frontend Build (`build-static`)
|
|
183
|
+
### 7.1 Frontend Build
|
|
189
184
|
|
|
190
|
-
Build
|
|
185
|
+
Build your frontend using Vite directly:
|
|
191
186
|
|
|
192
187
|
```bash
|
|
193
|
-
vite
|
|
188
|
+
vite build
|
|
194
189
|
```
|
|
195
190
|
|
|
196
|
-
**What it does:**
|
|
197
|
-
|
|
198
|
-
1. Runs `vite build` to compile your frontend to `dist/`
|
|
199
|
-
|
|
200
191
|
**Output:**
|
|
201
192
|
|
|
202
193
|
```
|
|
@@ -207,89 +198,97 @@ dist/
|
|
|
207
198
|
|
|
208
199
|
Deploy to any static host (Cloudflare Pages, Netlify, Vercel, etc.)
|
|
209
200
|
|
|
210
|
-
### 7.2 Server Build (`
|
|
201
|
+
### 7.2 Server Build (`--outDir`)
|
|
211
202
|
|
|
212
203
|
Build the Elysia API server into a standalone JavaScript bundle.
|
|
213
204
|
|
|
214
205
|
```bash
|
|
215
|
-
vite-elysia-forge build
|
|
206
|
+
vite-elysia-forge build --outDir dist
|
|
216
207
|
```
|
|
217
208
|
|
|
218
209
|
**What it does:**
|
|
219
210
|
|
|
220
211
|
1. Generates a production entry file that imports your API
|
|
221
|
-
2. Bundles the server into `
|
|
212
|
+
2. Bundles the server into `dist/server.js`
|
|
222
213
|
|
|
223
214
|
**package.json:**
|
|
224
215
|
|
|
225
216
|
```json
|
|
226
217
|
{
|
|
227
218
|
"scripts": {
|
|
228
|
-
"build:server": "vite-elysia-forge build
|
|
229
|
-
"start": "bun
|
|
219
|
+
"build:server": "vite-elysia-forge build --outDir dist",
|
|
220
|
+
"start": "bun dist/server.js"
|
|
230
221
|
}
|
|
231
222
|
}
|
|
232
223
|
```
|
|
233
224
|
|
|
234
|
-
**
|
|
225
|
+
**With custom entry and target:**
|
|
235
226
|
|
|
236
227
|
```bash
|
|
237
|
-
vite-elysia-forge build-
|
|
228
|
+
vite-elysia-forge build --entry src/my-api.ts --outDir .output --target node
|
|
238
229
|
```
|
|
239
230
|
|
|
240
|
-
### 7.3 Compiled Binary (`
|
|
231
|
+
### 7.3 Compiled Binary (`--outFile`)
|
|
241
232
|
|
|
242
|
-
Build
|
|
233
|
+
Build and compile the server into a **standalone executable** (no Bun runtime required).
|
|
243
234
|
|
|
244
235
|
```bash
|
|
245
|
-
vite-elysia-forge build
|
|
236
|
+
vite-elysia-forge build --outFile server
|
|
246
237
|
```
|
|
247
238
|
|
|
248
239
|
**What it does:**
|
|
249
240
|
|
|
250
|
-
1.
|
|
251
|
-
2. Compiles
|
|
241
|
+
1. Bundles the server code
|
|
242
|
+
2. Compiles into a native binary at the specified path
|
|
252
243
|
|
|
253
244
|
**package.json:**
|
|
254
245
|
|
|
255
246
|
```json
|
|
256
247
|
{
|
|
257
248
|
"scripts": {
|
|
258
|
-
"build:server": "vite-elysia-forge build
|
|
259
|
-
"start": "./
|
|
249
|
+
"build:server": "vite-elysia-forge build --outFile dist/server",
|
|
250
|
+
"start": "./dist/server"
|
|
260
251
|
}
|
|
261
252
|
}
|
|
262
253
|
```
|
|
263
254
|
|
|
264
255
|
### 7.4 CLI Reference
|
|
265
256
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
257
|
+
**Command:**
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
vite-elysia-forge build [options]
|
|
261
|
+
```
|
|
271
262
|
|
|
272
263
|
**Options:**
|
|
273
264
|
|
|
274
|
-
| Option
|
|
275
|
-
|
|
|
276
|
-
| `--
|
|
277
|
-
| `--
|
|
265
|
+
| Option | Short | Default | Description |
|
|
266
|
+
| :------------------ | :---: | :-------------- | :----------------------------------------- |
|
|
267
|
+
| `--entry <path>` | `-e` | `server/api.ts` | Path to API entry file |
|
|
268
|
+
| `--outDir <dir>` | `-d` | `dist` | Output directory for bundled `server.js` |
|
|
269
|
+
| `--outFile <file>` | `-o` | — | Output path for compiled standalone binary |
|
|
270
|
+
| `--target <target>` | `-t` | `bun` | Build target: `bun`, `node`, or `browser` |
|
|
271
|
+
| `--no-minify` | — | — | Disable minification |
|
|
272
|
+
|
|
273
|
+
> **Note:** `--outDir` and `--outFile` are mutually exclusive. Use `--outDir` for a bundled JS file, or `--outFile` for a compiled binary.
|
|
278
274
|
|
|
279
275
|
**Examples:**
|
|
280
276
|
|
|
281
277
|
```bash
|
|
282
|
-
#
|
|
283
|
-
vite-elysia-forge build
|
|
278
|
+
# Bundle server to dist/server.js
|
|
279
|
+
vite-elysia-forge build --outDir dist
|
|
280
|
+
|
|
281
|
+
# Bundle with node target
|
|
282
|
+
vite-elysia-forge build --outDir dist --target node
|
|
284
283
|
|
|
285
|
-
#
|
|
286
|
-
vite-elysia-forge build
|
|
284
|
+
# Compile to standalone binary
|
|
285
|
+
vite-elysia-forge build --outFile server
|
|
287
286
|
|
|
288
|
-
#
|
|
289
|
-
vite-elysia-forge build
|
|
287
|
+
# Compile with custom entry
|
|
288
|
+
vite-elysia-forge build --entry src/api/index.ts --outFile myserver
|
|
290
289
|
|
|
291
|
-
#
|
|
292
|
-
vite-elysia-forge build
|
|
290
|
+
# Bundle without minification
|
|
291
|
+
vite-elysia-forge build --outDir dist --no-minify
|
|
293
292
|
```
|
|
294
293
|
|
|
295
294
|
### 7.5 Deployment Architecture
|
|
@@ -301,20 +300,20 @@ vite-elysia-forge build-compile --server dist
|
|
|
301
300
|
│ Static Host │ │ API Server │
|
|
302
301
|
│ (CDN/Pages) │◄────────┤ (VPS/Cloud) │
|
|
303
302
|
│ │ CORS │ │
|
|
304
|
-
│ dist/ │ │
|
|
303
|
+
│ dist/ │ │ dist/server.js │
|
|
305
304
|
└─────────────────┘ └──────────────────┘
|
|
306
305
|
```
|
|
307
306
|
|
|
308
|
-
- Frontend:
|
|
309
|
-
- Backend:
|
|
307
|
+
- Frontend: Build with `vite build` and deploy to Cloudflare Pages, Netlify, Vercel, etc.
|
|
308
|
+
- Backend: Build with `vite-elysia-forge build --outDir dist` and deploy to any server with Bun installed, or use the compiled binary
|
|
310
309
|
|
|
311
310
|
**API-only deployment:**
|
|
312
311
|
|
|
313
312
|
If you have no frontend, just build and deploy the server:
|
|
314
313
|
|
|
315
314
|
```bash
|
|
316
|
-
vite-elysia-forge build
|
|
317
|
-
bun
|
|
315
|
+
vite-elysia-forge build --outDir dist
|
|
316
|
+
bun dist/server.js
|
|
318
317
|
```
|
|
319
318
|
|
|
320
319
|
## 8. Troubleshooting
|
|
@@ -355,7 +354,7 @@ If you see `Current adapter doesn't support WebSocket`, you need to enable WS mo
|
|
|
355
354
|
|
|
356
355
|
```ts
|
|
357
356
|
elysiaPlugin({
|
|
358
|
-
serverFile: "./
|
|
357
|
+
serverFile: "./server/api.ts",
|
|
359
358
|
ws: true,
|
|
360
359
|
});
|
|
361
360
|
```
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Bun build target options.
|
|
4
|
+
*/
|
|
5
|
+
type BuildTarget = "bun" | "node" | "browser";
|
|
6
|
+
/**
|
|
7
|
+
* Build options for the server bundle.
|
|
4
8
|
*/
|
|
5
9
|
interface BuildOptions {
|
|
6
10
|
/**
|
|
7
11
|
* Path to the API entry file.
|
|
8
|
-
* @default "
|
|
12
|
+
* @default "server/api.ts"
|
|
9
13
|
*/
|
|
10
|
-
|
|
14
|
+
entry?: string;
|
|
11
15
|
/**
|
|
12
|
-
* Output directory for the
|
|
13
|
-
*
|
|
16
|
+
* Output directory for the server bundle (used with --outDir).
|
|
17
|
+
* Mutually exclusive with outFile.
|
|
14
18
|
*/
|
|
15
|
-
|
|
19
|
+
outDir?: string;
|
|
16
20
|
/**
|
|
17
|
-
* Output
|
|
18
|
-
*
|
|
19
|
-
* will be built to separate directories.
|
|
20
|
-
* @default "dist" (same as staticDir)
|
|
21
|
+
* Output file path for compiled standalone binary (used with --outFile).
|
|
22
|
+
* Mutually exclusive with outDir.
|
|
21
23
|
*/
|
|
22
|
-
|
|
24
|
+
outFile?: string;
|
|
23
25
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @default false
|
|
26
|
+
* Build target for Bun.build.
|
|
27
|
+
* @default "bun"
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
|
+
target?: BuildTarget;
|
|
29
30
|
/**
|
|
30
|
-
* Whether to
|
|
31
|
-
*
|
|
32
|
-
* @default false
|
|
31
|
+
* Whether to minify the output.
|
|
32
|
+
* @default true
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
minify?: boolean;
|
|
35
35
|
}
|
|
36
|
-
declare function build(options?: BuildOptions
|
|
37
|
-
declare function buildCompile(options?: BuildOptions | string): Promise<void>;
|
|
36
|
+
declare function build(options?: BuildOptions): Promise<void>;
|
|
38
37
|
|
|
39
|
-
export { type BuildOptions,
|
|
38
|
+
export { type BuildOptions, type BuildTarget, build };
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import {spawnSync}from'child_process';import {existsSync,mkdirSync,writeFileSync,unlinkSync,rmSync}from'fs';import {resolve,relative,sep}from'path';async function
|
|
2
|
+
import {spawnSync}from'child_process';import {existsSync,mkdirSync,writeFileSync,unlinkSync,rmSync}from'fs';import {resolve,relative,sep,dirname}from'path';async function w(t={}){let o=t.entry||"server/api.ts",r=t.target||"bun",n=t.minify!==false,e=resolve(process.cwd(),o);existsSync(e)||(console.error(`\u274C API entry file "${o}" not found.`),console.error(' By default, vite-elysia-forge looks for "server/api.ts".'),console.error(" If your API is located elsewhere, please specify the path:"),console.error(" $ vite-elysia-forge build --entry <path-to-your-api-file>"),process.exit(1));let s=resolve(process.cwd(),".vef-temp");existsSync(s)||mkdirSync(s,{recursive:true});let i=resolve(s,".temp-prod.ts"),l=relative(s,e);l=l.split(sep).join("/"),l.startsWith(".")||(l="./"+l);let p=`
|
|
3
3
|
import { Elysia } from "elysia";
|
|
4
4
|
import { api } from ${JSON.stringify(l)};
|
|
5
5
|
|
|
@@ -9,7 +9,7 @@ if (api) app.use(api);
|
|
|
9
9
|
const port = process.env.PORT ? parseInt(process.env.PORT) : 3000;
|
|
10
10
|
app.listen(port);
|
|
11
11
|
|
|
12
|
-
console.log(\`Production server running at http
|
|
13
|
-
`;writeFileSync(u,
|
|
14
|
-
\u{
|
|
15
|
-
\u{1F4A1} To run:
|
|
12
|
+
console.log(\`Production server running at http://\${app?.server?.hostname}:\${app?.server?.port}\`);
|
|
13
|
+
`;writeFileSync(i,p);try{if(t.outFile)await D(i,t.outFile,r,n);else {let u=t.outDir||"dist";await x(i,u,r,n);}}finally{existsSync(i)&&unlinkSync(i),existsSync(s)&&rmSync(s,{recursive:true,force:true});}}async function x(t,o,r,n){let e=resolve(process.cwd(),o);existsSync(e)||mkdirSync(e,{recursive:true}),console.log(`\u{1F4E6} Building server to "${o}/" (target: ${r})...`);try{let s=await Bun.build({entrypoints:[t],outdir:e,target:r,minify:n,naming:"server.js"});if(!s.success){console.error("\u274C Server build failed");for(let i of s.logs)console.error(i);process.exit(1);}console.log(`\u2705 Server built to "${o}/server.js"`),console.log(`
|
|
14
|
+
\u{1F4A1} To run: bun ${o}/server.js`);}catch(s){console.error("\u274C Failed to build server. Ensure you are running this command with Bun."),console.error(s),process.exit(1);}}async function D(t,o,r,n){let e=resolve(process.cwd(),o),s=dirname(e);existsSync(s)||mkdirSync(s,{recursive:true});let i=resolve(process.cwd(),".vef-temp-bundle");existsSync(i)||mkdirSync(i,{recursive:true}),console.log(`\u{1F4E6} Building and compiling server to "${o}" (target: ${r})...`);try{let l=await Bun.build({entrypoints:[t],outdir:i,target:r,minify:n,naming:"server.js"});if(!l.success){console.error("\u274C Server build failed");for(let f of l.logs)console.error(f);process.exit(1);}let p=resolve(i,"server.js"),u=spawnSync("bun",["build","--compile",p,"--outfile",e],{stdio:"inherit",env:{...process.env,NODE_ENV:"production"}});u.status!==0&&(console.error("\u274C Bun compile failed"),process.exit(u.status||1)),console.log(`\u2705 Compiled standalone binary: ${o}`),console.log(`
|
|
15
|
+
\u{1F4A1} To run: ./${o}`);}catch(l){console.error("\u274C Failed to compile server. Ensure you are running this command with Bun."),console.error(l),process.exit(1);}finally{existsSync(i)&&rmSync(i,{recursive:true,force:true});}}function O(t){let o={};for(let r=0;r<t.length;r++){let n=t[r],e=t[r+1];switch(n){case "--entry":case "-e":e&&!e.startsWith("-")&&(o.entry=e,r++);break;case "--outDir":case "-d":e&&!e.startsWith("-")&&(o.outDir=e,r++);break;case "--outFile":case "-o":e&&!e.startsWith("-")&&(o.outFile=e,r++);break;case "--target":case "-t":e&&!e.startsWith("-")&&(o.target=e,r++);break;case "--no-minify":o.minify=false;break}}return o}if(import.meta.main){let t=process.argv.slice(2),o=t[0],r=t.slice(1);if(o==="build"){let n=O(r);n.outDir&&n.outFile&&(console.error("\u274C Cannot use both --outDir and --outFile. Choose one."),process.exit(1)),w(n);}else console.log("Usage: vite-elysia-forge build [options]"),console.log(""),console.log("Build the Elysia server for production."),console.log(""),console.log("Options:"),console.log(" --entry, -e <path> Path to API entry file (default: server/api.ts)"),console.log(" --outDir, -d <dir> Output directory for bundled server.js"),console.log(" --outFile, -o <file> Output path for compiled standalone binary"),console.log(" --target, -t <target> Build target: bun, node, browser (default: bun)"),console.log(" --no-minify Disable minification"),console.log(""),console.log("Examples:"),console.log(" # Bundle server to dist/server.js"),console.log(" vite-elysia-forge build --outDir dist"),console.log(""),console.log(" # Bundle with node target"),console.log(" vite-elysia-forge build --outDir dist --target node"),console.log(""),console.log(" # Compile to standalone binary"),console.log(" vite-elysia-forge build --outFile server"),console.log(""),console.log(" # Compile with custom entry"),console.log(" vite-elysia-forge build --entry src/api/index.ts --outFile myserver");}export{w as build};
|