Skip to content

Commit f0ed9f5

Browse files
committed
improve information regarding bundle global context
1 parent 0d6345c commit f0ed9f5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

en/build-config.md

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = merge(baseConfig, {
3636
externals: nodeExternals({
3737
// do not externalize dependencies that need to be processed by webpack.
3838
// you can add more file types here e.g. raw *.vue files
39+
// you should also whitelist deps that modifies `global` (e.g. polyfills)
3940
whitelist: /\.css$/
4041
}),
4142

@@ -59,6 +60,12 @@ const renderer = createBundleRenderer('/path/to/vue-ssr-server-bundle.json', {
5960

6061
Alternatively, you can also pass the bundle as an Object to `createBundleRenderer`. This is useful for hot-reload during development - see the HackerNews demo for a [reference setup](https://github.com/vuejs/vue-hackernews-2.0/blob/master/build/setup-dev-server.js).
6162

63+
### Externals Caveats
64+
65+
Notice that in the `externals` option we are whitelisting CSS files. This is because CSS imported from dependencies should still be handled by webpack. If you are importing any other types of files that also rely on webpack (e.g. `*.vue`, `*.sass`), you should add them to the whitelist as well.
66+
67+
Another type of modules to whitelist are polyfills that modify `global`, e.g. `babel-polyfill`. This is because **code inside a server bundle has its own `global` object.** Since you don't really need it on the server when using Node 7.6+, it's actually easier to just import it in the client entry.
68+
6269
## Client Config
6370

6471
The client config can remain largely the same with the base config. Obviously you need to point `entry` to your client entry file. Aside from that, if you are using `CommonsChunkPlugin`, make sure to use it only in the client config because the server bundle requires a single entry chunk.

en/bundle-renderer.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ When `rendertoString` is called on a bundle renderer, it will automatically exec
5353

5454
### The `runInNewContext` Option
5555

56-
By default, for each render the bundle renderer will create a fresh V8 context and re-execute the entire bundle. This has some benefits - for example, we don't need to worry about the "stateful singleton" problem we mentioned earlier. However, this mode comes at some considerable performance cost because re-executing the bundle is expensive especially when the app gets bigger.
56+
By default, for each render the bundle renderer will create a fresh V8 context and re-execute the entire bundle. This has some benefits - for example, we don't need to worry about the "stateful singleton" problem we mentioned earlier. However, this mode comes at some considerable performance cost because re-executing the entire bundle is expensive especially when the app gets bigger.
5757

5858
In `vue-server-renderer >= 2.3.0`, this option still defaults to `true` for backwards compatibility, but it is recommended to use `runInNewContext: false` whenever you can.
59+
60+
Note that when using `runInNewContext: false`, the bundle is still **evaluated in a separate `global` context**, however only once. This prevents the bundle accidentally polluting the server process' `global` object. The difference from the default behavior is that it will not create **new** contexts for each render call.

0 commit comments

Comments
 (0)