From ffb9c65f4622b01cdb7bb0386f7ce3915e4b905a Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Sun, 17 May 2020 20:39:17 +0100 Subject: [PATCH] feat(ssr): add non async split chunk to preload scripts (#7383) --- packages/webpack/src/plugins/vue/client.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/webpack/src/plugins/vue/client.js b/packages/webpack/src/plugins/vue/client.js index afa44180a8..91faab8aea 100644 --- a/packages/webpack/src/plugins/vue/client.js +++ b/packages/webpack/src/plugins/vue/client.js @@ -47,6 +47,7 @@ export default class VueSSRClientPlugin { assetsMapping } + const { entrypoints, namedChunkGroups } = stats const assetModules = stats.modules.filter(m => m.assets.length) const fileToIndex = file => manifest.all.indexOf(file) stats.modules.forEach((m) => { @@ -58,7 +59,21 @@ export default class VueSSRClientPlugin { return } const id = m.identifier.replace(/\s\w+$/, '') // remove appended hash - const files = manifest.modules[hash(id)] = chunk.files.map(fileToIndex) + const filesSet = new Set(chunk.files.map(fileToIndex)) + + for (const chunkName of chunk.names) { + if (!entrypoints[chunkName]) { + const chunkGroup = namedChunkGroups[chunkName] + if (chunkGroup) { + for (const asset of chunkGroup.assets) { + filesSet.add(fileToIndex(asset)) + } + } + } + } + + const files = Array.from(filesSet) + manifest.modules[hash(id)] = files // In production mode, modules may be concatenated by scope hoisting // Include ConcatenatedModule for not losing module-component mapping