Skip to content

Commit 83e7b6c

Browse files
committed
fix(bundler-webpack): partially fix ssr dependencies issue
1 parent b4afa32 commit 83e7b6c

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

.vscode/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
"type": "node-terminal",
1616
"request": "launch",
1717
"command": "pnpm docs:build"
18+
},
19+
{
20+
"name": "docs:dev (webpack)",
21+
"type": "node-terminal",
22+
"request": "launch",
23+
"command": "DOCS_BUNDLER=webpack pnpm docs:dev"
24+
},
25+
{
26+
"name": "docs:build (webpack)",
27+
"type": "node-terminal",
28+
"request": "launch",
29+
"command": "DOCS_BUNDLER=webpack pnpm docs:build"
1830
}
1931
]
2032
}

packages/bundler-webpack/src/build/build.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,8 @@ export const build = async (
7979
const clientManifest: ClientManifest = await fs.readJson(clientManifestPath)
8080

8181
// resolve client files meta
82-
const {
83-
allFilesMeta,
84-
initialFilesMeta,
85-
asyncFilesMeta,
86-
moduleFilesMetaMap,
87-
} = resolveClientManifestMeta(clientManifest)
82+
const { initialFilesMeta, asyncFilesMeta, moduleFilesMetaMap } =
83+
resolveClientManifestMeta(clientManifest)
8884

8985
// load the compiled server bundle
9086
const serverEntryPath = app.dir.temp('.server/app.cjs')
@@ -107,7 +103,6 @@ export const build = async (
107103
vueRouter,
108104
renderToString,
109105
ssrTemplate,
110-
allFilesMeta,
111106
initialFilesMeta,
112107
asyncFilesMeta,
113108
moduleFilesMetaMap,

packages/bundler-webpack/src/build/renderPage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export const renderPage = async ({
3131
vueRouter,
3232
renderToString,
3333
ssrTemplate,
34-
allFilesMeta,
3534
initialFilesMeta,
3635
asyncFilesMeta,
3736
moduleFilesMetaMap,
@@ -42,7 +41,6 @@ export const renderPage = async ({
4241
vueRouter: Router
4342
renderToString: (input: VueApp, context: SSRContext) => Promise<string>
4443
ssrTemplate: string
45-
allFilesMeta: FileMeta[]
4644
initialFilesMeta: FileMeta[]
4745
asyncFilesMeta: FileMeta[]
4846
moduleFilesMetaMap: ModuleFilesMetaMap

packages/bundler-webpack/src/build/ssr/createClientPlugin.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,14 @@ export const createClientPlugin = (
2424
'vuepress-client-plugin',
2525
async (compilation) => {
2626
// get webpack stats object
27-
const stats: StatsToJsonOutput = compilation
28-
.getStats()
29-
.toJson() as unknown as StatsToJsonOutput
30-
3127
const {
3228
assets = [],
3329
modules = [],
3430
entrypoints = {},
3531
chunks = [],
36-
} = stats
32+
}: StatsToJsonOutput = compilation
33+
.getStats()
34+
.toJson() as unknown as StatsToJsonOutput
3735

3836
// get all files
3937
const allFiles = assets.map((a) => a.name)

packages/bundler-webpack/src/build/ssr/vuepressLoader.cts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ module.exports = function vuepressLoader(source: string): string {
1212
// get `request` from loader context
1313
const { request } = this as any
1414

15+
if (!request.endsWith('.vue')) return source
16+
1517
// add `request` to `ssrContext._registeredComponents` to handle SSR dependencies
18+
// notice that this could only handle those sfc that cannot use inline template
19+
// see https://github.com/vuejs/vue-loader/blob/1b1a195612f885a8dec3f371edf1cb8b35d341e4/src/index.ts#L167-L183
1620
return source.replace(
17-
'script.ssrRender = ssrRender',
18-
`\
21+
/import { ssrRender } from (.*)\n/,
22+
`import { ssrRender as _ssrRender } from $1
1923
import { ssrContextKey } from 'vue'
20-
script.ssrRender = (...args) => {
24+
const ssrRender = (...args) => {
2125
const ssrContext = args[2].appContext.provides[ssrContextKey]
2226
ssrContext._registeredComponents.add(${JSON.stringify(request)})
23-
return ssrRender(...args)
27+
return _ssrRender(...args)
2428
}
2529
`
2630
)

0 commit comments

Comments
 (0)