vite-elysia-forge 0.0.8 → 0.0.9
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 -10
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -57,11 +57,22 @@ Run Vite as usual and access your API at `/api/*` routes. The plugin will automa
|
|
|
57
57
|
bun run dev
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
## 3.
|
|
60
|
+
## 3. Configuration Options
|
|
61
|
+
|
|
62
|
+
### 3.1 Plugin Options
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
elysiaPlugin({
|
|
66
|
+
// Path to your Elysia API module (relative to project root)
|
|
67
|
+
serverFile?: string; // default: "/server/api.ts"
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 4. API Module Requirements
|
|
61
72
|
|
|
62
73
|
Your API module must export an Elysia instance with a `handle(request: Request) => Promise<Response>` method.
|
|
63
74
|
|
|
64
|
-
###
|
|
75
|
+
### 4.1 Basic Example
|
|
65
76
|
|
|
66
77
|
```ts
|
|
67
78
|
import { Elysia } from "elysia";
|
|
@@ -76,7 +87,7 @@ api.get("/users", () => ["user1", "user2"]);
|
|
|
76
87
|
export default api;
|
|
77
88
|
```
|
|
78
89
|
|
|
79
|
-
##
|
|
90
|
+
## 5. Integration with @elysiajs/openapi
|
|
80
91
|
|
|
81
92
|
To use the [@elysiajs/openapi plugin](https://elysiajs.com/patterns/openapi), add the following to your `tsconfig.json`:
|
|
82
93
|
|
|
@@ -89,7 +100,7 @@ To use the [@elysiajs/openapi plugin](https://elysiajs.com/patterns/openapi), ad
|
|
|
89
100
|
}
|
|
90
101
|
```
|
|
91
102
|
|
|
92
|
-
###
|
|
103
|
+
### 5.1 Example with `fromTypes`
|
|
93
104
|
|
|
94
105
|
It is recommended to pre-generate the declaration file (`.d.ts`) to provide type declaration to the generator.
|
|
95
106
|
|
|
@@ -104,9 +115,9 @@ const app = new Elysia().use(
|
|
|
104
115
|
);
|
|
105
116
|
```
|
|
106
117
|
|
|
107
|
-
##
|
|
118
|
+
## 6. Production Deployment
|
|
108
119
|
|
|
109
|
-
###
|
|
120
|
+
### 6.1 Build Configuration
|
|
110
121
|
|
|
111
122
|
Update your `package.json` scripts:
|
|
112
123
|
|
|
@@ -126,7 +137,7 @@ If your API is located elsewhere, specify the path:
|
|
|
126
137
|
vite-elysia-forge build src/my-api.ts
|
|
127
138
|
```
|
|
128
139
|
|
|
129
|
-
###
|
|
140
|
+
### 6.2 Building for Production
|
|
130
141
|
|
|
131
142
|
Run the build command:
|
|
132
143
|
|
|
@@ -140,7 +151,7 @@ This command performs the following steps:
|
|
|
140
151
|
2. Automatically generates a temporary entry file that imports your API from `src/server/api.ts`
|
|
141
152
|
3. Bundles the server into a single file at `dist/server.js`
|
|
142
153
|
|
|
143
|
-
###
|
|
154
|
+
### 6.3 Starting the Production Server
|
|
144
155
|
|
|
145
156
|
Start the server with:
|
|
146
157
|
|
|
@@ -148,10 +159,42 @@ Start the server with:
|
|
|
148
159
|
bun start
|
|
149
160
|
```
|
|
150
161
|
|
|
151
|
-
##
|
|
162
|
+
## 7. Troubleshooting
|
|
163
|
+
|
|
164
|
+
### 7.1 "Bun is not defined" Error
|
|
165
|
+
|
|
166
|
+
If you encounter this error, ensure you are running Vite with the Bun runtime:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
bunx --bun vite
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Or update your `dev` script in `package.json`:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
"scripts": {
|
|
176
|
+
"dev": "bunx --bun vite"
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Benefits:**
|
|
181
|
+
|
|
182
|
+
- **Access to Bun APIs:** You can use `Bun.file`, `Bun.env`, `bun:sqlite`, and other native Bun features directly in your server code.
|
|
183
|
+
- **Performance:** Vite often starts faster and uses less memory when running under Bun.
|
|
184
|
+
|
|
185
|
+
**Caveats:**
|
|
186
|
+
|
|
187
|
+
- **Node.js Compatibility:** While Bun has excellent Node.js compatibility, some Vite plugins that rely on obscure Node.js internals might behave unexpectedly.
|
|
188
|
+
- **Performance:** Running Vite under Bun is generally faster, but you might encounter edge cases where optimization differs from Node.js.
|
|
189
|
+
|
|
190
|
+
### 7.2 Hot Reload Not Working
|
|
191
|
+
|
|
192
|
+
Check that your file changes are within the dependency graph of your API module. The plugin uses Vite's dependency tracking to determine when to reload.
|
|
193
|
+
|
|
194
|
+
## 8. Authors
|
|
152
195
|
|
|
153
196
|
- Chijioke Udokporo ([@chijiokeudokporo](https://github.com/chijioke-udokporo))
|
|
154
197
|
|
|
155
|
-
##
|
|
198
|
+
## 9. License
|
|
156
199
|
|
|
157
200
|
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var path=require('path');function
|
|
1
|
+
'use strict';var path=require('path');function E({serverFile:g="/server/api.ts"}={}){return {name:"vite-elysia-forge",async configureServer(s){let l=g,y=path.resolve(s.config.root,l.slice(1)),f=async()=>(await s.ssrLoadModule(l)).api,p=await f();s.watcher.add(y),s.watcher.on("change",async e=>{let o=await s.moduleGraph.getModuleByUrl(l);if(!o)return;let i=s.moduleGraph.getModulesByFile(e);if(!i||i.size===0)return;let n=false,r=new Set,a=[...i];for(;a.length>0;){let t=a.shift();if(!(!t||!t.id||r.has(t.id))){if(r.add(t.id),t.id===o.id){n=true;break}for(let c of t.importers)a.push(c);}}if(n)try{s.moduleGraph.invalidateModule(o),p=await f(),console.log("[vite-elysia-forge] Reloaded Elysia API module");}catch(t){console.error(`[vite-elysia-forge] Failed to reload Elysia API: ${t}`);}}),s.middlewares.use(async(e,o,i)=>{if(!e.url?.startsWith("/api"))return i();try{let n="http",r=e.headers.host||"localhost:3000",a=`${n}://${r}${e.url}`,t;if(e.method!=="GET"&&e.method!=="HEAD"){let d=[];for await(let h of e)d.push(h);t=Buffer.concat(d).toString();}let c=new Request(a,{method:e.method,headers:e.headers,body:t}),u=await p.handle(c);o.statusCode=u.status,u.headers.forEach((d,h)=>{o.setHeader(h,d);});let m=await u.text();o.end(m);}catch(n){console.error(`[vite-elysia-forge] Elysia error: ${n}`),o.statusCode=500,o.end("Internal Server Error");}});}}}var P=E;
|
|
2
2
|
module.exports=P;
|
package/dist/index.d.cts
CHANGED
|
@@ -20,6 +20,6 @@ interface ConfigOptions {
|
|
|
20
20
|
* @param options - Configuration options for the plugin.
|
|
21
21
|
* @returns A Vite plugin instance.
|
|
22
22
|
*/
|
|
23
|
-
declare function elysiaPlugin({ serverFile }
|
|
23
|
+
declare function elysiaPlugin({ serverFile }?: ConfigOptions): Plugin;
|
|
24
24
|
|
|
25
25
|
export { type ConfigOptions, elysiaPlugin as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,6 @@ interface ConfigOptions {
|
|
|
20
20
|
* @param options - Configuration options for the plugin.
|
|
21
21
|
* @returns A Vite plugin instance.
|
|
22
22
|
*/
|
|
23
|
-
declare function elysiaPlugin({ serverFile }
|
|
23
|
+
declare function elysiaPlugin({ serverFile }?: ConfigOptions): Plugin;
|
|
24
24
|
|
|
25
25
|
export { type ConfigOptions, elysiaPlugin as default };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {resolve}from'path';function
|
|
1
|
+
import {resolve}from'path';function E({serverFile:g="/server/api.ts"}={}){return {name:"vite-elysia-forge",async configureServer(s){let l=g,y=resolve(s.config.root,l.slice(1)),f=async()=>(await s.ssrLoadModule(l)).api,p=await f();s.watcher.add(y),s.watcher.on("change",async e=>{let o=await s.moduleGraph.getModuleByUrl(l);if(!o)return;let i=s.moduleGraph.getModulesByFile(e);if(!i||i.size===0)return;let n=false,r=new Set,a=[...i];for(;a.length>0;){let t=a.shift();if(!(!t||!t.id||r.has(t.id))){if(r.add(t.id),t.id===o.id){n=true;break}for(let c of t.importers)a.push(c);}}if(n)try{s.moduleGraph.invalidateModule(o),p=await f(),console.log("[vite-elysia-forge] Reloaded Elysia API module");}catch(t){console.error(`[vite-elysia-forge] Failed to reload Elysia API: ${t}`);}}),s.middlewares.use(async(e,o,i)=>{if(!e.url?.startsWith("/api"))return i();try{let n="http",r=e.headers.host||"localhost:3000",a=`${n}://${r}${e.url}`,t;if(e.method!=="GET"&&e.method!=="HEAD"){let d=[];for await(let h of e)d.push(h);t=Buffer.concat(d).toString();}let c=new Request(a,{method:e.method,headers:e.headers,body:t}),u=await p.handle(c);o.statusCode=u.status,u.headers.forEach((d,h)=>{o.setHeader(h,d);});let m=await u.text();o.end(m);}catch(n){console.error(`[vite-elysia-forge] Elysia error: ${n}`),o.statusCode=500,o.end("Internal Server Error");}});}}}var P=E;
|
|
2
2
|
export{P as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-elysia-forge",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
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",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "chijioke-udokporo",
|
|
14
14
|
"private": false,
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "bun run test && tsup",
|
|
16
|
+
"build": "rm -rf dist &&bun run test && tsup",
|
|
17
17
|
"test": "bun test"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {},
|