fix(modern): wrong assets mapping in ssr client modern mode (#7382)

This commit is contained in:
Xin Du (Clark) 2020-05-17 20:41:07 +01:00 committed by GitHub
parent ffb9c65f46
commit b1b14033fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,3 @@
import invert from 'lodash/invert'
import { isUrl, urlJoin, safariNoModuleFix } from '@nuxt/utils'
import SSRRenderer from './ssr'
@ -17,13 +16,15 @@ export default class ModernRenderer extends SSRRenderer {
const { clientManifest, modernManifest } = this.serverContext.resources
const legacyAssets = clientManifest.assetsMapping
const modernAssets = invert(modernManifest.assetsMapping)
const modernAssets = modernManifest.assetsMapping
const mapping = {}
for (const legacyJsFile in legacyAssets) {
const chunkNamesHash = legacyAssets[legacyJsFile]
mapping[legacyJsFile] = modernAssets[chunkNamesHash]
}
Object.keys(legacyAssets).forEach((componentHash) => {
const modernComponentAssets = modernAssets[componentHash] || []
legacyAssets[componentHash].forEach((legacyAssetName, index) => {
mapping[legacyAssetName] = modernComponentAssets[index]
})
})
delete clientManifest.assetsMapping
delete modernManifest.assetsMapping
this._assetsMapping = mapping

View File

@ -35,7 +35,11 @@ export default class VueSSRClientPlugin {
stats.assets
.filter(({ name }) => isJS(name))
.forEach(({ name, chunkNames }) => {
assetsMapping[name] = hash(chunkNames.join('|'))
const componentHash = hash(chunkNames.join('|'))
if (!assetsMapping[componentHash]) {
assetsMapping[componentHash] = []
}
assetsMapping[componentHash].push(name)
})
const manifest = {