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 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 `src/server/api.ts` (default path):
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: "./src/server/api.ts",
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: "./src/server/api.ts",
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 commands for separate frontend and backend deployment. Frontend and backend are **always built separately** for independent deployment.
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 `src/server/api.ts`. You can specify a custom path with the `--api` flag:
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
- ```bash
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 the frontend static assets.
185
+ Build your frontend using Vite directly:
191
186
 
192
187
  ```bash
193
- vite-elysia-forge build-static
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 (`build-server`)
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-server
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 `build/server.js` (default)
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-server",
229
- "start": "bun build/server.js"
219
+ "build:server": "vite-elysia-forge build --outDir dist",
220
+ "start": "bun dist/server.js"
230
221
  }
231
222
  }
232
223
  ```
233
224
 
234
- **Custom output directory:**
225
+ **With custom entry and target:**
235
226
 
236
227
  ```bash
237
- vite-elysia-forge build-server --server .output
228
+ vite-elysia-forge build --entry src/my-api.ts --outDir .output --target node
238
229
  ```
239
230
 
240
- ### 7.3 Compiled Binary (`build-compile`)
231
+ ### 7.3 Compiled Binary (`--outFile`)
241
232
 
242
- Build the server and compile it into a **standalone executable** (no Bun runtime required).
233
+ Build and compile the server into a **standalone executable** (no Bun runtime required).
243
234
 
244
235
  ```bash
245
- vite-elysia-forge build-compile
236
+ vite-elysia-forge build --outFile server
246
237
  ```
247
238
 
248
239
  **What it does:**
249
240
 
250
- 1. Performs the server build
251
- 2. Compiles `build/server.js` into a native binary at `build/server`
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-compile",
259
- "start": "./build/server"
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
- | Command | Description |
267
- | :-------------- | :-------------------------------------------- |
268
- | `build-static` | Build frontend static assets only |
269
- | `build-server` | Build API server bundle (JavaScript) |
270
- | `build-compile` | Build and compile server to native executable |
257
+ **Command:**
258
+
259
+ ```bash
260
+ vite-elysia-forge build [options]
261
+ ```
271
262
 
272
263
  **Options:**
273
264
 
274
- | Option | Short | Default | Description |
275
- | :--------------- | :---: | :------------------ | :-------------------------- |
276
- | `--api <path>` | `-a` | `src/server/api.ts` | Path to API entry file |
277
- | `--server <dir>` | `-o` | `build` | Output directory for server |
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
- # Build frontend
283
- vite-elysia-forge build-static
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
- # Build server with custom API path
286
- vite-elysia-forge build-server --api src/my-api.ts
284
+ # Compile to standalone binary
285
+ vite-elysia-forge build --outFile server
287
286
 
288
- # Build server to custom directory
289
- vite-elysia-forge build-server --server .output
287
+ # Compile with custom entry
288
+ vite-elysia-forge build --entry src/api/index.ts --outFile myserver
290
289
 
291
- # Build compiled binary
292
- vite-elysia-forge build-compile --server dist
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/ │ │ build/server.js
303
+ │ dist/ │ │ dist/server.js
305
304
  └─────────────────┘ └──────────────────┘
306
305
  ```
307
306
 
308
- - Frontend: Deploy `dist/` to Cloudflare Pages, Netlify, Vercel, etc.
309
- - Backend: Deploy `build/server.js` to any server with Bun installed, or use the compiled binary
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-server
317
- bun build/server.js
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: "./src/server/api.ts",
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
- * Build options for customizing output directories.
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 "src/server/api.ts"
12
+ * @default "server/api.ts"
9
13
  */
10
- apiEntry?: string;
14
+ entry?: string;
11
15
  /**
12
- * Output directory for the Vite/frontend static assets.
13
- * @default "dist"
16
+ * Output directory for the server bundle (used with --outDir).
17
+ * Mutually exclusive with outFile.
14
18
  */
15
- staticDir?: string;
19
+ outDir?: string;
16
20
  /**
17
- * Output directory for the Elysia server bundle.
18
- * When set to a different value than staticDir, the server and static assets
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
- serverDir?: string;
24
+ outFile?: string;
23
25
  /**
24
- * Whether to skip the Vite frontend build.
25
- * Useful when you only want to rebuild the server.
26
- * @default false
26
+ * Build target for Bun.build.
27
+ * @default "bun"
27
28
  */
28
- skipVite?: boolean;
29
+ target?: BuildTarget;
29
30
  /**
30
- * Whether to skip the server build.
31
- * Useful when you only want to rebuild the frontend.
32
- * @default false
31
+ * Whether to minify the output.
32
+ * @default true
33
33
  */
34
- skipServer?: boolean;
34
+ minify?: boolean;
35
35
  }
36
- declare function build(options?: BuildOptions | string): Promise<void>;
37
- declare function buildCompile(options?: BuildOptions | string): Promise<void>;
36
+ declare function build(options?: BuildOptions): Promise<void>;
38
37
 
39
- export { type BuildOptions, build, buildCompile };
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 f(r={}){let e=typeof r=="string"?{apiEntry:r}:r,o=e.apiEntry||"src/server/api.ts",s=e.staticDir||"dist",t=e.serverDir||s,p=e.skipVite||false,v=e.skipServer||false,h=s!==t,g=resolve(process.cwd(),o);if(!v&&!existsSync(g)&&(console.error(`\u274C API entry file "${o}" not found.`),console.error(' By default, vite-elysia-forge looks for "src/server/api.ts".'),console.error(" If your API is located elsewhere, please specify the path:"),console.error(" $ vite-elysia-forge build --api <path-to-your-api-file>"),process.exit(1)),!p){console.log(`\u{1F4E6} Building frontend to "${s}"...`);let i=spawnSync("bun",["x","vite","build","--outDir",s],{stdio:"inherit",env:{...process.env,NODE_ENV:"production"}});i.status!==0&&(console.error("\u274C Vite build failed"),process.exit(i.status||1)),console.log(`\u2705 Frontend built to "${s}"`);}if(v){console.log("\u23ED\uFE0F Skipping server build (--skip-server)");return}let n=resolve(process.cwd(),".output");existsSync(n)||mkdirSync(n,{recursive:true});let u=resolve(n,".temp-prod.ts"),l=relative(n,g);l=l.split(sep).join("/"),l.startsWith(".")||(l="./"+l);let k=`
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://localhost:\${port}\`);
13
- `;writeFileSync(u,k);let y=resolve(process.cwd(),t);existsSync(y)||mkdirSync(y,{recursive:true}),console.log(`\u{1F4E6} Building server to "${t}"...`);try{let i=await Bun.build({entrypoints:[u],outdir:t,target:"bun",minify:!0,naming:"server.js"});if(!i.success){console.error("\u274C Server build failed");for(let S of i.logs)console.error(S);process.exit(1);}console.log(`\u2705 Server built to "${t}/server.js"`);}catch(i){console.error("\u274C Failed to build server. Ensure you are running this command with Bun."),console.error(i),process.exit(1);}finally{existsSync(u)&&unlinkSync(u),existsSync(n)&&rmSync(n,{recursive:true,force:true});}h&&(console.log(`
14
- \u{1F4C1} Output structure:`),console.log(` Static assets: ${s}/`),console.log(` Server bundle: ${t}/server.js`),console.log(`
15
- \u{1F4A1} To run: cd ${t} && bun server.js`),console.log(" Or set STATIC_DIR to override the static assets path"));}async function P(r={}){let e=typeof r=="string"?{apiEntry:r}:r,o=e.serverDir||e.staticDir||"dist";await f(e),console.log("\u{1F527} Compiling server to standalone binary...");let s=resolve(process.cwd(),o,"server.js"),t=resolve(process.cwd(),o,"server"),p=spawnSync("bun",["build","--compile",s,"--outfile",t],{stdio:"inherit",env:{...process.env,NODE_ENV:"production"}});p.status!==0&&(console.error("\u274C Bun compile failed"),process.exit(p.status||1)),console.log(`\u2705 Compiled standalone binary: ${o}/server`);}function d(r){let e={};for(let o=0;o<r.length;o++){let s=r[o],t=r[o+1];switch(s){case "--api":case "-a":t&&!t.startsWith("-")&&(e.apiEntry=t,o++);break;case "--static":case "-s":t&&!t.startsWith("-")&&(e.staticDir=t,o++);break;case "--server":case "-o":t&&!t.startsWith("-")&&(e.serverDir=t,o++);break;case "--skip-vite":e.skipVite=true;break;case "--skip-server":e.skipServer=true;break;default:s&&!s.startsWith("-")&&!e.apiEntry&&(e.apiEntry=s);}}return e}if(import.meta.main){let r=process.argv.slice(2),e=r[0],o=r.slice(1);if(e==="build"){let s=d(o);f(s);}else if(e==="build-compile"){let s=d(o);P(s);}else if(e==="build-static"){let s=d(o);s.skipServer=true,f(s);}else if(e==="build-server"){let s=d(o);s.skipVite=true,f(s);}else console.log("Usage: vite-elysia-forge <command> [options]"),console.log(""),console.log("Commands:"),console.log(" build Build frontend + bundle server"),console.log(" build-compile Build and compile a standalone server binary"),console.log(" build-static Build only the frontend (skip server)"),console.log(" build-server Build only the server (skip frontend)"),console.log(""),console.log("Options:"),console.log(" --api, -a <path> Path to API entry file (default: src/server/api.ts)"),console.log(" --static, -s <dir> Output directory for static assets (default: dist)"),console.log(" --server, -o <dir> Output directory for server bundle (default: same as --static)"),console.log(" --skip-vite Skip the Vite frontend build"),console.log(" --skip-server Skip the server build"),console.log(""),console.log("Examples:"),console.log(" # Build everything to 'dist/' (default)"),console.log(" vite-elysia-forge build"),console.log(""),console.log(" # Build with separate output directories"),console.log(" vite-elysia-forge build --static dist --server .output"),console.log(""),console.log(" # Build only the frontend"),console.log(" vite-elysia-forge build-static --static public"),console.log(""),console.log(" # Build only the server to a separate folder"),console.log(" vite-elysia-forge build-server --server .output --static dist");}export{f as build,P as buildCompile};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-elysia-forge",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A Vite plugin to seamlessly integrate ElysiaJS for full-stack development with Bun runtime.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",