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
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