Skip to content

Commit 7ccff1b

Browse files
committed
docs: update readme
1 parent 6f030f9 commit 7ccff1b

File tree

2 files changed

+68
-13
lines changed

2 files changed

+68
-13
lines changed

README.md

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,71 @@ Vite plugin for vue Server-Side Rendering, Used express to create a server.
66

77
## Usage
88

9+
### Install
10+
11+
```bash
12+
# npm
13+
npm install -D vite-ssr-vue3 vue-router
14+
15+
# yarn
16+
yarn add -D vite-ssr-vue3 vue-router
17+
18+
# pnpm
19+
pnpm add -D vite-ssr-vue3 vue-router
20+
21+
# pnpm workspaces
22+
pnpm add -D vite-ssr-vue3 vue-router -F <Repo Name>
23+
```
24+
25+
Modify `package.json` scripts to:
26+
27+
```diff
28+
{
29+
"scripts": {
30+
- "dev": "vite --port 3333",
31+
+ "dev": "vite-ssr --port 3333",
32+
- "build": "vite build",
33+
+ "build": "vite-ssr build",
34+
+ "serve": "vite-ssr --mode production"
35+
},
36+
}
37+
```
38+
939
```ts
40+
// src/main.ts
1041
import { ViteSSR } from 'vite-ssr-vue3'
1142
import routes from './routes'
1243
import App from './App.vue'
1344

45+
// Export `createApp` function is required by vite-ssr
1446
export const createApp = ViteSSR(App, { routes }, (context) => {
15-
const { app, initialState } = context
16-
1747
// if (import.meta.env.SSR) {
1848
// // Running in server
1949
// } else {
2050
// // Running in browser
2151
// }
52+
})
53+
```
54+
55+
### Initial State
56+
57+
```ts
58+
// src/main.ts
59+
import { ViteSSR } from 'vite-ssr-vue3'
60+
import routes from './routes'
61+
import App from './App.vue'
62+
63+
export const createApp = ViteSSR(App, { routes }, (context) => {
64+
const { app, initialState } = context
2265

2366
// Use pinia to store your data
2467
const pinia = createPinia()
2568

2669
if (import.meta.env.SSR)
2770
initialState.pinia = pinia.state.value
28-
2971
else
3072
pinia.state.value = initialState.pinia
3173

32-
// do something
3374
})
3475
```
3576

@@ -41,15 +82,6 @@ import { useFetch } from 'vite-ssr-vue3'
4182
const counts = await useFetch('counts', () => Promise.resolve([1, 2, 3]))
4283
```
4384

44-
## Development
45-
46-
There are some examples in the **example** directory, you can execute the **package.json** script to start developing source with the sample.
47-
48-
First, you should install the dependencies with command `pnpm install`, then run the `pnpm basic:dev` command to start developing, run `pnpm basic:serve` to view production environment effects.
49-
50-
+ `example/basic`: Basic usage with data fetching example
51-
+ `example/naive-ui`: Naive UI example
52-
5385
## Thanks
5486

5587
Lots of references to the following repos.

examples/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# How to run/build the examples
2+
3+
```bash
4+
# Clone repo
5+
git clone https://github.com/aliuq/vite-ssr-vue3.git
6+
cd vite-ssr-vue3
7+
8+
# Install all project dependencies and build project
9+
pnpm install
10+
pnpm build
11+
12+
# Basic example
13+
pnpm basic:dev
14+
pnpm basic:build
15+
pnpm basic:serve
16+
pnpm basic:preview
17+
18+
# Vitesse lite and naive-ui
19+
pnpm vl-naive:dev
20+
pnpm vl-naive:build
21+
pnpm vl-naive:serve
22+
pnpm vl-naive:preview
23+
```

0 commit comments

Comments
 (0)