vike-lite 1.9.0 → 1.10.0

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
@@ -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
- | Package Manager | Command
5
- | - | -
6
- | **npm** | `npm install -D vike-lite`
7
- | **yarn** | `yarn add -D vike-lite`
8
- | **pnpm** | `pnpm add -D vike-lite`
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 Vite plugin
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 = 'pages', // Default
22
- serverEntry = 'server/index', // Default
23
- apiPrefix = '/api', // Default
24
- prerender = false // Default
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
- ### 🪝 Hooks
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 (pages) using custom rendering
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
- > Note: if you don't use a custom server (loaded by the `serverEntry` option), a default server is bundled. In PROD the server is started as follow:
64
- ```ts
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).
@@ -7,5 +7,6 @@
7
7
  declare function navigate(url: string, options?: {
8
8
  keepScrollPosition?: boolean;
9
9
  }): void;
10
+ declare const reload: () => Promise<void>;
10
11
  //#endregion
11
- export { navigate };
12
+ export { navigate, reload };
@@ -12,5 +12,10 @@ function navigate(url, options) {
12
12
  globalThis.history.pushState(null, "", 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 };
package/dist/server.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  //#region src/server/renderPage.d.ts
2
2
  declare function renderPage(req: Request, {
3
3
  nonce
4
- }: {
4
+ }?: {
5
5
  nonce?: string;
6
6
  }): Promise<Response>;
7
7
  //#endregion
package/dist/server.mjs CHANGED
@@ -132,7 +132,7 @@ async function renderErrorPage(req, status, urlPathname, error, nonce) {
132
132
  return new Response(status === 404 ? "Not Found" : "Internal Server Error", { status });
133
133
  }
134
134
  }
135
- async function renderPage(req, { nonce }) {
135
+ async function renderPage(req, { nonce } = {}) {
136
136
  let { pathname } = new URL(req.url);
137
137
  if (BASE_URL !== "/") {
138
138
  const baseSlashed = BASE_URL.endsWith("/") ? BASE_URL : BASE_URL + "/";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",