vike-lite 1.9.1 → 1.10.1
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 +33 -23
- package/dist/client/router.d.mts +2 -1
- package/dist/client/router.mjs +7 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,39 +1,51 @@
|
|
|
1
1
|
# vike-lite
|
|
2
2
|
|
|
3
|
+
A lightweight, fast, and minimal framework for Server-Side Rendering (SSR) and Static Site Generation (SSG) inspired by [Vike](https://vike.dev).
|
|
4
|
+
|
|
3
5
|
### ⚙️ Install
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
Install `vike-lite`
|
|
7
|
+
```sh
|
|
8
|
+
# npm
|
|
9
|
+
npm install -D vike-lite
|
|
10
|
+
|
|
11
|
+
# pnpm
|
|
12
|
+
pnpm add -D vike-lite
|
|
13
|
+
|
|
14
|
+
# yarn
|
|
15
|
+
yarn add -D vike-lite
|
|
16
|
+
```
|
|
9
17
|
|
|
10
18
|
### 📖 Usage
|
|
11
|
-
Add
|
|
19
|
+
Add the `vike-lite` plugin to your `vite.config`.
|
|
12
20
|
|
|
13
21
|
```ts
|
|
14
22
|
// vite.config.ts
|
|
15
|
-
import type { UserConfig } from 'vite'
|
|
16
23
|
import vikeLite from 'vike-lite/vite'
|
|
24
|
+
import type { UserConfig } from 'vite'
|
|
17
25
|
|
|
18
26
|
export default {
|
|
19
27
|
plugins: [
|
|
20
28
|
vikeLite({
|
|
21
|
-
pagesDir
|
|
22
|
-
serverEntry
|
|
23
|
-
apiPrefix
|
|
24
|
-
prerender
|
|
29
|
+
pagesDir: 'pages', // Default: Directory containing your pages
|
|
30
|
+
serverEntry: 'server/index', // Default: Custom server entry file
|
|
31
|
+
apiPrefix: '/api', // Default: Prefix to bypass SSR for API routes
|
|
32
|
+
prerender: false // Default: Enable SSG globally
|
|
25
33
|
})
|
|
26
34
|
]
|
|
27
35
|
} satisfies UserConfig
|
|
28
36
|
```
|
|
29
37
|
|
|
30
|
-
###
|
|
38
|
+
### 🖥️ Server Integration
|
|
39
|
+
|
|
40
|
+
#### `renderPage()`
|
|
41
|
+
If you want to use a custom server (like Hono, Express, or Fastify), you can use the renderPage utility to handle your frontend routes.
|
|
42
|
+
|
|
43
|
+
Here is an example using Hono:
|
|
31
44
|
|
|
32
|
-
#### renderPage
|
|
33
45
|
```ts
|
|
34
46
|
// /server/index.ts
|
|
35
|
-
import { cors } from 'hono/cors'
|
|
36
47
|
import { Hono } from 'hono'
|
|
48
|
+
import { cors } from 'hono/cors'
|
|
37
49
|
import { renderPage } from 'vike-lite/server'
|
|
38
50
|
|
|
39
51
|
import apiRoutes from './apiRoutes'
|
|
@@ -44,14 +56,17 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
44
56
|
app.use(cors())
|
|
45
57
|
}
|
|
46
58
|
|
|
59
|
+
// 1. Handle API routes first
|
|
47
60
|
app.route('/api', apiRoutes)
|
|
48
61
|
|
|
49
|
-
// Catch-all remaining requests
|
|
62
|
+
// 2. Catch-all remaining requests and pass them to vike-lite
|
|
50
63
|
app.get('*', async (c, next) => {
|
|
51
64
|
const response = await renderPage(c.req.raw)
|
|
65
|
+
// If vike-lite successfully renders a page, return it. Otherwise, continue.
|
|
52
66
|
return response ?? next()
|
|
53
67
|
})
|
|
54
68
|
|
|
69
|
+
// 3. Error Handling
|
|
55
70
|
app.onError((error, c) => {
|
|
56
71
|
console.error(error)
|
|
57
72
|
return c.json({ error: 'Internal Server Error' }, 500)
|
|
@@ -60,18 +75,13 @@ app.onError((error, c) => {
|
|
|
60
75
|
export default app
|
|
61
76
|
```
|
|
62
77
|
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
>💡 **Note on Default Server:** if you don't need a custom backend and skip the `serverEntry` option, `vike-lite` bundles a default server for you out of the box. In production, it will be automatically started via an auto-generated entry point:
|
|
79
|
+
|
|
80
|
+
```mjs
|
|
65
81
|
// startServer.mjs
|
|
66
82
|
import './dist/server/index.mjs'
|
|
67
83
|
```
|
|
68
84
|
|
|
69
|
-
### 🫶 Contribution
|
|
70
|
-
Clone
|
|
71
|
-
```sh
|
|
72
|
-
git clone https://github.com/node-ecosystem/vike-lite.git
|
|
73
|
-
```
|
|
74
|
-
|
|
75
85
|
---
|
|
76
86
|
|
|
77
87
|
This project is licensed under the [MIT License](../../LICENSE).
|
package/dist/client/router.d.mts
CHANGED
package/dist/client/router.mjs
CHANGED
|
@@ -9,8 +9,13 @@ function navigate(url, options) {
|
|
|
9
9
|
if (typeof globalThis === "undefined") throw new Error("navigate() can only be called on the client side.");
|
|
10
10
|
let finalUrl = url;
|
|
11
11
|
if (finalUrl.startsWith("/")) finalUrl = (BASE_URL.endsWith("/") ? BASE_URL.slice(0, -1) : BASE_URL) + (finalUrl === "/" ? "" : finalUrl);
|
|
12
|
-
globalThis.history.pushState(
|
|
12
|
+
globalThis.history.pushState({ triggeredBy: "vike-lite" }, "", finalUrl);
|
|
13
13
|
globalThis.dispatchEvent(new CustomEvent("vike-navigate", { detail: { keepScrollPosition: options?.keepScrollPosition } }));
|
|
14
14
|
}
|
|
15
|
+
const reload = () => {
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
globalThis.dispatchEvent(new CustomEvent("vike-reload", { detail: { resolve } }));
|
|
18
|
+
});
|
|
19
|
+
};
|
|
15
20
|
//#endregion
|
|
16
|
-
export { navigate };
|
|
21
|
+
export { navigate, reload };
|