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

View File

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