fix(vue-renderer): use modulepreload for modern mode spa generate (#5489)

This commit is contained in:
Xin Du (Clark) 2019-04-08 18:43:57 +01:00 committed by Pooya Parsa
parent 8b15af79e7
commit 87fcf556a4

View File

@ -30,8 +30,9 @@ export default class SPAMetaRenderer {
return vm.$meta().inject() return vm.$meta().inject()
} }
async render({ url = '/', req = {} }) { async render({ url = '/', req = {}, _generate }) {
const cacheKey = `${req.modernMode ? 'modern:' : 'legacy:'}${url}` const modern = req.modernMode || (this.options.modern && _generate)
const cacheKey = `${modern ? 'modern:' : 'legacy:'}${url}`
let meta = this.cache.get(cacheKey) let meta = this.cache.get(cacheKey)
if (meta) { if (meta) {
@ -75,7 +76,7 @@ export default class SPAMetaRenderer {
meta.resourceHints = '' meta.resourceHints = ''
const { resources: { modernManifest, clientManifest } } = this.renderer.context const { resources: { modernManifest, clientManifest } } = this.renderer.context
const manifest = req.modernMode ? modernManifest : clientManifest const manifest = modern ? modernManifest : clientManifest
const { shouldPreload, shouldPrefetch } = this.options.render.bundleRenderer const { shouldPreload, shouldPrefetch } = this.options.render.bundleRenderer
@ -90,7 +91,7 @@ export default class SPAMetaRenderer {
meta.preloadFiles = manifest.initial meta.preloadFiles = manifest.initial
.map(SPAMetaRenderer.normalizeFile) .map(SPAMetaRenderer.normalizeFile)
.filter(({ fileWithoutQuery, asType }) => shouldPreload(fileWithoutQuery, asType)) .filter(({ fileWithoutQuery, asType }) => shouldPreload(fileWithoutQuery, asType))
.map(file => ({ ...file, modern: req.modernMode })) .map(file => ({ ...file, modern }))
meta.resourceHints += meta.preloadFiles meta.resourceHints += meta.preloadFiles
.map(({ file, extension, fileWithoutQuery, asType, modern }) => { .map(({ file, extension, fileWithoutQuery, asType, modern }) => {