@lomray/vite-ssr-boost 1.0.0-beta.7 → 1.0.0-beta.8
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 +207 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
<h1 align='center'>Vite SSR BOOST</h1>
|
|
2
|
+
|
|
3
|
+
- Develop ⚡charged⚡ server side applications with React streaming 💨 support.
|
|
4
|
+
- Unlocks Suspense for server side applications.
|
|
5
|
+
- Switch between SPA and SSR in 1 second.
|
|
6
|
+
- Charged CLI out of box.
|
|
7
|
+
- Very easy to migrate, very easy to use.
|
|
8
|
+
- All the power of [vite](https://vitejs.dev/)⚡
|
|
9
|
+
- All the power of [react-router](https://reactrouter.com/)🛣
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=reliability_rating" alt="reliability">
|
|
13
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=security_rating" alt="Security Rating">
|
|
14
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=sqale_rating" alt="Maintainability Rating">
|
|
15
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=vulnerabilities" alt="Vulnerabilities">
|
|
16
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=bugs" alt="Bugs">
|
|
17
|
+
<img src="https://sonarcloud.io/api/project_badges/measure?project=vite-ssr-boost&metric=ncloc" alt="Lines of Code">
|
|
18
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@lomray/vite-ssr-boost" alt="size">
|
|
19
|
+
<img src="https://img.shields.io/npm/l/@lomray/vite-ssr-boost" alt="size">
|
|
20
|
+
<img src="https://img.shields.io/npm/v/@lomray/vite-ssr-boost?label=semantic%20release&logo=semantic-release" alt="semantic version">
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
## Table of contents
|
|
24
|
+
- [Getting started](#getting-started)
|
|
25
|
+
- [How to use](#how-to-use)
|
|
26
|
+
- [Plugin options](#plugin-options)
|
|
27
|
+
- [CLI](#cli)
|
|
28
|
+
- [Example](#demo)
|
|
29
|
+
- [Bugs and feature requests](#bugs-and-feature-requests)
|
|
30
|
+
- [License](#license)
|
|
31
|
+
|
|
32
|
+
## Getting started
|
|
33
|
+
|
|
34
|
+
The package is distributed using [npm](https://www.npmjs.com/), the node package manager.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
npm i --save @lomray/vite-ssr-boost
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## How to use
|
|
41
|
+
|
|
42
|
+
1. Add plugin to vite config:
|
|
43
|
+
```typescript
|
|
44
|
+
/**
|
|
45
|
+
* vite.config.ts
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
import { defineConfig } from 'vite'
|
|
49
|
+
import react from '@vitejs/plugin-react'
|
|
50
|
+
/**
|
|
51
|
+
* Import plugin
|
|
52
|
+
*/
|
|
53
|
+
import SsrBoost from '@lomray/vite-ssr-boost/plugin';
|
|
54
|
+
|
|
55
|
+
// https://vitejs.dev/config/
|
|
56
|
+
export default defineConfig({
|
|
57
|
+
/**
|
|
58
|
+
* Change root not necessary, but more understandable
|
|
59
|
+
*/
|
|
60
|
+
root: 'src',
|
|
61
|
+
publicDir: '../public',
|
|
62
|
+
build: {
|
|
63
|
+
outDir: '../build',
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Put here
|
|
67
|
+
*/
|
|
68
|
+
plugins: [SsrBoost(), react()],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
2. Create `client` entrypoint:
|
|
73
|
+
|
|
74
|
+
```typescript jsx
|
|
75
|
+
/**
|
|
76
|
+
* src/client.tsx
|
|
77
|
+
*/
|
|
78
|
+
import entryClient from '@lomray/vite-ssr-boost/browser/entry';
|
|
79
|
+
import App from './App.tsx'
|
|
80
|
+
import routes from './routes';
|
|
81
|
+
|
|
82
|
+
void entryClient(App, routes, {
|
|
83
|
+
/**
|
|
84
|
+
* Client configuration (optional)
|
|
85
|
+
*/
|
|
86
|
+
init: () => {}
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
3. Create `server` entrypoint:
|
|
91
|
+
|
|
92
|
+
```typescript jsx
|
|
93
|
+
/**
|
|
94
|
+
* src/server.ts
|
|
95
|
+
*/
|
|
96
|
+
import entryServer from '@lomray/vite-ssr-boost/node/entry';
|
|
97
|
+
import App from './App';
|
|
98
|
+
import routes from './routes';
|
|
99
|
+
|
|
100
|
+
export default entryServer(App, routes, {
|
|
101
|
+
/**
|
|
102
|
+
* Server configuration (optional)
|
|
103
|
+
*/
|
|
104
|
+
init: () => ({
|
|
105
|
+
/**
|
|
106
|
+
* (optional). Called once after express server creation.
|
|
107
|
+
* E.g. use for configure express middlewares
|
|
108
|
+
*/
|
|
109
|
+
onServerCreated: () => {},
|
|
110
|
+
/**
|
|
111
|
+
* (optional). Called on each incoming request.
|
|
112
|
+
* E.g. configure request state, create state manager etc.
|
|
113
|
+
*/
|
|
114
|
+
onRequest: async () => {},
|
|
115
|
+
/**
|
|
116
|
+
* (optional). Called when react router and it's context was created.
|
|
117
|
+
* E.g. here you can switch stream depends on req.headers, for search crawlers you can disable stream.
|
|
118
|
+
*/
|
|
119
|
+
onRouterReady: () => {},
|
|
120
|
+
/**
|
|
121
|
+
* (optional). Called when application shell is ready to send on client.
|
|
122
|
+
* E.g. here you can modify header or footer.
|
|
123
|
+
*/
|
|
124
|
+
onShellReady: () => {},
|
|
125
|
+
/**
|
|
126
|
+
* (optional). Called when application shell or suspense resolved and sent to the client.
|
|
127
|
+
* E.g. here you can add some payload like custom state (any manager state) to response.
|
|
128
|
+
*/
|
|
129
|
+
onResponse: () => {},
|
|
130
|
+
/**
|
|
131
|
+
* (optional). Called when application shell or all html (depends on stream option) is ready to send on client.
|
|
132
|
+
* E.g. here you can send any context or state to client.
|
|
133
|
+
*/
|
|
134
|
+
getState: () => {},
|
|
135
|
+
}),
|
|
136
|
+
}, App);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
4. Replace `package.json` scripts:
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
...
|
|
144
|
+
"scripts": {
|
|
145
|
+
"develop": "ssr-boost dev",
|
|
146
|
+
"build": "ssr-boost build",
|
|
147
|
+
"start:ssr": "ssr-boost start",
|
|
148
|
+
"start:spa": "ssr-boost start --only-client",
|
|
149
|
+
"preview": "ssr-boost preview"
|
|
150
|
+
},
|
|
151
|
+
...
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
5. Let's do the magic:
|
|
156
|
+
|
|
157
|
+
```shell
|
|
158
|
+
npm run develop
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Plugin options
|
|
162
|
+
```typescript
|
|
163
|
+
import SsrBoost from '@lomray/vite-ssr-boost/plugin';
|
|
164
|
+
import type { FCRoute } from '@lomray/vite-ssr-boost/interfaces/fc-route';
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Configuration
|
|
168
|
+
*/
|
|
169
|
+
SsrBoost({
|
|
170
|
+
/**
|
|
171
|
+
* With this option you can export route components like FCRoute or FCCRoute
|
|
172
|
+
* @example
|
|
173
|
+
* const Page: FCRoute = () => <div>Hi</div>;
|
|
174
|
+
*
|
|
175
|
+
* Page.ErrorBoudary = () => <div>Error</div>;
|
|
176
|
+
*
|
|
177
|
+
* export default Page;
|
|
178
|
+
*
|
|
179
|
+
* Routes:
|
|
180
|
+
* const routes = [{ path: '/', lazyNR: () => import('./pages/home') }]
|
|
181
|
+
*/
|
|
182
|
+
hasLazyRoutePlugin: true, // default: true
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Add tsconfig aliases to vite config aliases
|
|
186
|
+
*/
|
|
187
|
+
tsconfigAliases: true, // default: true
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## CLI
|
|
192
|
+
Explore all commands and options:
|
|
193
|
+
```shell
|
|
194
|
+
ssr-boost -h
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Demo
|
|
198
|
+
Explore [demo app](https://github.com/Lomray-Software/vite-template) to more understand.
|
|
199
|
+
|
|
200
|
+
## Bugs and feature requests
|
|
201
|
+
|
|
202
|
+
Bug or a feature request, [please open a new issue](https://github.com/Lomray-Software/vite-ssr-boost/issues/new).
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
Made with 💚
|
|
206
|
+
|
|
207
|
+
Published under [Apache License](./LICENSE).
|