|
|
|
@ -39,8 +39,7 @@ export async function renderPage(
|
|
|
|
|
))
|
|
|
|
|
const pageData = JSON.parse(__pageData)
|
|
|
|
|
|
|
|
|
|
const preloadLinks = (
|
|
|
|
|
config.mpa
|
|
|
|
|
let preloadLinks = config.mpa
|
|
|
|
|
? appChunk
|
|
|
|
|
? [appChunk.fileName]
|
|
|
|
|
: []
|
|
|
|
@ -56,12 +55,27 @@ export async function renderPage(
|
|
|
|
|
])
|
|
|
|
|
]
|
|
|
|
|
: []
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let prefetchLinks: string[] = []
|
|
|
|
|
|
|
|
|
|
const { shouldPreload } = config
|
|
|
|
|
if (shouldPreload) {
|
|
|
|
|
prefetchLinks = preloadLinks.filter((link) => !shouldPreload(link, page))
|
|
|
|
|
preloadLinks = preloadLinks.filter((link) => shouldPreload(link, page))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const preloadLinksString = preloadLinks
|
|
|
|
|
.map((file) => {
|
|
|
|
|
return `<link rel="modulepreload" href="${siteData.base}${file}">`
|
|
|
|
|
})
|
|
|
|
|
.join('\n ')
|
|
|
|
|
|
|
|
|
|
const prefetchLinkString = prefetchLinks
|
|
|
|
|
.map((file) => {
|
|
|
|
|
return `<link rel="prefetch" href="${siteData.base}${file}">`
|
|
|
|
|
})
|
|
|
|
|
.join('\n ')
|
|
|
|
|
|
|
|
|
|
const stylesheetLink = cssChunk
|
|
|
|
|
? `<link rel="stylesheet" href="${siteData.base}${cssChunk.fileName}">`
|
|
|
|
|
: ''
|
|
|
|
@ -105,7 +119,8 @@ export async function renderPage(
|
|
|
|
|
pageData.description || siteData.description
|
|
|
|
|
}">
|
|
|
|
|
${stylesheetLink}
|
|
|
|
|
${preloadLinks}
|
|
|
|
|
${preloadLinksString}
|
|
|
|
|
${prefetchLinkString}
|
|
|
|
|
${renderHead(head)}
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
@ -135,7 +150,7 @@ function resolvePageImports(
|
|
|
|
|
appChunk: OutputChunk
|
|
|
|
|
) {
|
|
|
|
|
// find the page's js chunk and inject script tags for its imports so that
|
|
|
|
|
// they are start fetching as early as possible
|
|
|
|
|
// they start fetching as early as possible
|
|
|
|
|
const srcPath = normalizePath(
|
|
|
|
|
fs.realpathSync(path.resolve(config.srcDir, page))
|
|
|
|
|
)
|
|
|
|
|