fix: modulepreload warnings (#6118)

This commit is contained in:
Dzmitry Bachko 2019-07-24 13:01:33 -04:00 committed by Xin Du (Clark)
parent c6f0f5d954
commit 76b1167d27
2 changed files with 6 additions and 3 deletions

View File

@ -113,9 +113,11 @@ const defaultPushAssets = (preloadFiles, shouldPush, publicPath, options) => {
const { crossorigin } = options.build const { crossorigin } = options.build
const cors = `${crossorigin ? ` crossorigin=${crossorigin};` : ''}` const cors = `${crossorigin ? ` crossorigin=${crossorigin};` : ''}`
const ref = modern ? 'modulepreload' : 'preload' // `modulepreload` rel attribute only supports script-like `as` value
// https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload
const rel = modern && asType === 'script' ? 'modulepreload' : 'preload'
links.push(`<${publicPath}${file}>; rel=${ref};${cors} as=${asType}`) links.push(`<${publicPath}${file}>; rel=${rel};${cors} as=${asType}`)
}) })
return links return links
} }

View File

@ -109,7 +109,8 @@ export default class SPARenderer extends BaseRenderer {
if (asType === 'font') { if (asType === 'font') {
extra = ` type="font/${extension}"${cors ? '' : ' crossorigin'}` extra = ` type="font/${extension}"${cors ? '' : ' crossorigin'}`
} }
return `<link rel="${modern ? 'module' : ''}preload"${cors} href="${publicPath}${file}"${ const rel = modern && asType === 'script' ? 'modulepreload' : 'preload'
return `<link rel="${rel}"${cors} href="${publicPath}${file}"${
asType !== '' ? ` as="${asType}"` : ''}${extra}>` asType !== '' ? ` as="${asType}"` : ''}${extra}>`
}) })
.join('') .join('')