You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/vue-server-renderer/README.md
+60-24
Original file line number
Diff line number
Diff line change
@@ -110,34 +110,16 @@ bundleRenderer
110
110
111
111
## Renderer Options
112
112
113
-
### directives
114
-
115
-
Allows you to provide server-side implementations for your custom directives:
116
-
117
-
```js
118
-
constrenderer=createRenderer({
119
-
directives: {
120
-
example (vnode, directiveMeta) {
121
-
// transform vnode based on directive binding metadata
122
-
}
123
-
}
124
-
})
125
-
```
126
-
127
-
As an example, check out [`v-show`'s server-side implementation](https://github.com/vuejs/vue/blob/dev/src/platforms/web/server/directives/show.js).
128
-
129
-
---
130
-
131
113
### cache
132
114
133
-
Provide a [component cache](#component-caching) implementation. The cache object must implement the following interface:
115
+
Provide a [component cache](#component-caching) implementation. The cache object must implement the following interface (using Flow notations):
Provide a template for the entire page's HTML. The template should contain a comment `<!--vue-ssr-outlet-->` which serves as the placeholder for rendered app content.
162
+
163
+
In addition, when both a template and a render context is provided (e.g. when using the `bundleRenderer`), the renderer will also automatically inject the following properties found on the render context:
164
+
165
+
-`context.head`: (string) any head markup that should be injected into the head of the page. Note when using the bundle format generated with `vue-ssr-webpack-plugin`, this property will automatically contain `<link rel="preload/prefetch">` directives for chunks in the bundle.
166
+
167
+
-`context.styles`: (string) any inline CSS that should be injected into the head of the page. Note that `vue-loader` 10.2.0+ (which uses `vue-style-loader` 2.0) will automatically populate this property with styles used in rendered components.
168
+
169
+
-`context.state`: (Object) initial Vuex store state that should be inlined in the page as `window.__INITIAL_STATE__`. The inlined JSON is automatically sanitized with [serialize-javascript](https://github.com/yahoo/serialize-javascript).
170
+
171
+
**Example:**
172
+
173
+
```js
174
+
constrenderer=createRenderer({
175
+
template:
176
+
'<!DOCTYPE html>'+
177
+
'<html lang="en">'+
178
+
'<head>'+
179
+
'<meta charset="utf-8">'+
180
+
// context.head will be injected here
181
+
// context.styles will be injected here
182
+
'</head>'+
183
+
'<body>'+
184
+
'<!--vue-ssr-outlet-->'+// <- app content rendered here
185
+
// context.state will be injected here
186
+
'</body>'+
187
+
'</html>'
188
+
})
189
+
```
190
+
191
+
---
192
+
193
+
### directives
194
+
195
+
Allows you to provide server-side implementations for your custom directives:
196
+
197
+
```js
198
+
constrenderer=createRenderer({
199
+
directives: {
200
+
example (vnode, directiveMeta) {
201
+
// transform vnode based on directive binding metadata
202
+
}
203
+
}
204
+
})
205
+
```
206
+
207
+
As an example, check out [`v-show`'s server-side implementation](https://github.com/vuejs/vue/blob/dev/src/platforms/web/server/directives/show.js).
208
+
173
209
## Why Use `bundleRenderer`?
174
210
175
211
In a typical Node.js app, the server is a long-running process. If we directly require our application code, the instantiated modules will be shared across every request. This imposes some inconvenient restrictions to the application structure: we will have to avoid any use of global stateful singletons (e.g. the store), otherwise state mutations caused by one request will affect the result of the next.
0 commit comments