File tree Expand file tree Collapse file tree 2 files changed +30
-30
lines changed
packages/bundler-webpack/src/loaders Expand file tree Collapse file tree 2 files changed +30
-30
lines changed Original file line number Diff line number Diff line change 1- import type { LoaderDefinitionFunction } from 'webpack'
2-
3- /**
4- * A webpack loader to handle SSR dependencies
5- *
6- * This loader will only take effect in server bundle
7- * because we only replace `ssrRender` code
8- *
9- * But we still need to use this loader in client,
10- * to ensure that the module `request` in client and
11- * server bundle are the same
12- */
13- const vuepressSsrLoader : LoaderDefinitionFunction = function ( source ) {
14- if ( ! this . request . endsWith ( '.vue' ) ) return source
15-
16- // add `request` to `ssrContext._registeredComponents` to handle SSR dependencies
17- // notice that this could only handle those sfc that cannot use inline template
18- // see https://github.com/vuejs/vue-loader/blob/1b1a195612f885a8dec3f371edf1cb8b35d341e4/src/index.ts#L167-L183
19- return source . replace (
20- / i m p o r t { s s r R e n d e r } f r o m ( .* ) \n / ,
21- `import { ssrRender as _ssrRender } from $1
22- import { ssrContextKey } from 'vue'
23- const ssrRender = (...args) => {
24- const ssrContext = args[2].appContext.provides[ssrContextKey]
25- ssrContext._registeredComponents.add(${ JSON . stringify ( this . request ) } )
26- return _ssrRender(...args)
27- }
28- ` ,
29- )
30- }
1+ const { vuepressSsrLoader } = require ( './vuepressSsrLoader.js' )
312
323module . exports = vuepressSsrLoader
Original file line number Diff line number Diff line change 1+ import type { LoaderDefinitionFunction } from 'webpack'
2+
3+ /**
4+ * A webpack loader to handle SSR dependencies
5+ *
6+ * This loader will only take effect in server bundle
7+ * because we only replace `ssrRender` code
8+ *
9+ * But we still need to use this loader in client,
10+ * to ensure that the module `request` in client and
11+ * server bundle are the same
12+ */
13+ export const vuepressSsrLoader : LoaderDefinitionFunction =
14+ function vuepressSsrLoader ( source ) {
15+ // add `request` to `ssrContext._registeredComponents` to handle SSR dependencies
16+ // notice that this could only handle those sfc that cannot use inline template
17+ // see https://github.com/vuejs/vue-loader/blob/1b1a195612f885a8dec3f371edf1cb8b35d341e4/src/index.ts#L167-L183
18+ return source . replace (
19+ / i m p o r t { s s r R e n d e r } f r o m ( .* ) \n / ,
20+ `import { ssrRender as _ssrRender } from $1
21+ import { ssrContextKey } from 'vue'
22+ const ssrRender = (...args) => {
23+ const ssrContext = args[2].appContext.provides[ssrContextKey]
24+ ssrContext._registeredComponents.add(${ JSON . stringify ( this . request ) } )
25+ return _ssrRender(...args)
26+ }
27+ ` ,
28+ )
29+ }
You can’t perform that action at this time.
0 commit comments