-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(bundler-webpack): split cjs loader entry
- Loading branch information
Showing
2 changed files
with
30 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,3 @@ | ||
import type { LoaderDefinitionFunction } from 'webpack' | ||
|
||
/** | ||
* A webpack loader to handle SSR dependencies | ||
* | ||
* This loader will only take effect in server bundle | ||
* because we only replace `ssrRender` code | ||
* | ||
* But we still need to use this loader in client, | ||
* to ensure that the module `request` in client and | ||
* server bundle are the same | ||
*/ | ||
const vuepressSsrLoader: LoaderDefinitionFunction = function (source) { | ||
if (!this.request.endsWith('.vue')) return source | ||
|
||
// add `request` to `ssrContext._registeredComponents` to handle SSR dependencies | ||
// notice that this could only handle those sfc that cannot use inline template | ||
// see https://github.com/vuejs/vue-loader/blob/1b1a195612f885a8dec3f371edf1cb8b35d341e4/src/index.ts#L167-L183 | ||
return source.replace( | ||
/import { ssrRender } from (.*)\n/, | ||
`import { ssrRender as _ssrRender } from $1 | ||
import { ssrContextKey } from 'vue' | ||
const ssrRender = (...args) => { | ||
const ssrContext = args[2].appContext.provides[ssrContextKey] | ||
ssrContext._registeredComponents.add(${JSON.stringify(this.request)}) | ||
return _ssrRender(...args) | ||
} | ||
`, | ||
) | ||
} | ||
const { vuepressSsrLoader } = require('./vuepressSsrLoader.js') | ||
|
||
module.exports = vuepressSsrLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { LoaderDefinitionFunction } from 'webpack' | ||
|
||
/** | ||
* A webpack loader to handle SSR dependencies | ||
* | ||
* This loader will only take effect in server bundle | ||
* because we only replace `ssrRender` code | ||
* | ||
* But we still need to use this loader in client, | ||
* to ensure that the module `request` in client and | ||
* server bundle are the same | ||
*/ | ||
export const vuepressSsrLoader: LoaderDefinitionFunction = | ||
function vuepressSsrLoader(source) { | ||
// add `request` to `ssrContext._registeredComponents` to handle SSR dependencies | ||
// notice that this could only handle those sfc that cannot use inline template | ||
// see https://github.com/vuejs/vue-loader/blob/1b1a195612f885a8dec3f371edf1cb8b35d341e4/src/index.ts#L167-L183 | ||
return source.replace( | ||
/import { ssrRender } from (.*)\n/, | ||
`import { ssrRender as _ssrRender } from $1 | ||
import { ssrContextKey } from 'vue' | ||
const ssrRender = (...args) => { | ||
const ssrContext = args[2].appContext.provides[ssrContextKey] | ||
ssrContext._registeredComponents.add(${JSON.stringify(this.request)}) | ||
return _ssrRender(...args) | ||
} | ||
`, | ||
) | ||
} |