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
Creates a `bundleRenderer` instance using pre-bundled application code (see [Creating the Server Bundle](#creating-the-server-bundle)). For each render call, the code will be re-run in a new context using Node.js' `vm` module. This ensures your application state is discrete between requests, and you don't need to worry about structuring your application in a limiting pattern just for the sake of SSR.
81
+
Creates a `bundleRenderer` instance using pre-compiled application bundle (see [Creating the Server Bundle](#creating-the-server-bundle)). For each render call, the code will be re-run in a new context using Node.js' `vm` module. This ensures your application state is discrete between requests, and you don't need to worry about structuring your application in a limiting pattern just for the sake of SSR.
@@ -180,11 +180,23 @@ Instead, it's more straightforward to run our app "fresh" for each request, so t
180
180
181
181
<imgwidth="973"alt="screen shot 2016-08-11 at 6 06 57 pm"src="https://cloud.githubusercontent.com/assets/499550/17607895/786a415a-5fee-11e6-9c11-45a2cfdf085c.png">
182
182
183
-
The application bundle can be generated by any build tool, so you can easily use Webpack + `vue-loader` with the bundleRenderer. You do need to use a slightly different webpack config and entry point for your server-side bundle, but the difference is rather minimal:
183
+
The application bundle can be either a string of bundled code, or a special object of the following type:
184
184
185
-
1. add `target: 'node'`, and use `output: { libraryTarget: 'commonjs2' }` for your webpack config. Also, it's probably a good idea to [externalize your dependencies](#externals).
185
+
```js
186
+
type RenderBundle = {
187
+
entry: string; // name of the entry file
188
+
files: { [filename: string]: string; }; // all files in the bundle
Although theoretically you can use any build tool to generate the bundle, it is recommended to use Webpack + `vue-loader` + [vue-ssr-webpack-plugin](https://github.com/vuejs/vue-ssr-webpack-plugin) for this purpose. The usual workflow is setting up a base webpack configuration file for the client-side, then modify it to generate the server-side bundle with the following changes:
186
194
187
-
2. In your server-side entry point, export a function. The function will receive the render context object (passed to `bundleRenderer.renderToString` or `bundleRenderer.renderToStream`), and should return a Promise, which should eventually resolve to the app's root Vue instance:
195
+
1. Set `target: 'node'` and `output: { libraryTarget: 'commonjs2' }` in your webpack config.
196
+
197
+
2. Add [vue-ssr-webpack-plugin](https://github.com/vuejs/vue-ssr-webpack-plugin) to your webpack plugins. This plugin automatically generates the bundle as a single JSON file which contains all the files and source maps of the entire bundle. This is particularly important if you use Webpack's code-splitting features that result in a multi-file bundle.
198
+
199
+
3. In your server-side entry point, export a function. The function will receive the render context object (passed to `bundleRenderer.renderToString` or `bundleRenderer.renderToStream`), and should return a Promise, which should eventually resolve to the app's root Vue instance:
188
200
189
201
```js
190
202
// server-entry.js
@@ -203,6 +215,8 @@ The application bundle can be generated by any build tool, so you can easily use
203
215
}
204
216
```
205
217
218
+
4. It's also a good idea to externalize your dependencies (see below).
219
+
206
220
### Externals
207
221
208
222
When using the `bundleRenderer`, we will by default bundle every dependency of our app into the server bundle as well. This means on each request these depdencies will need to be parsed and evaluated again, which is unnecessary in most cases.
0 commit comments