|
|
@ -2,9 +2,8 @@ import { isBooleanAttr } from '@vue/shared'
|
|
|
|
import escape from 'escape-html'
|
|
|
|
import escape from 'escape-html'
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
import fs from 'fs-extra'
|
|
|
|
import path from 'path'
|
|
|
|
import path from 'path'
|
|
|
|
import type { OutputAsset, OutputChunk, RollupOutput } from 'rollup'
|
|
|
|
|
|
|
|
import { pathToFileURL } from 'url'
|
|
|
|
import { pathToFileURL } from 'url'
|
|
|
|
import { normalizePath, transformWithEsbuild } from 'vite'
|
|
|
|
import { normalizePath, transformWithEsbuild, type Rollup } from 'vite'
|
|
|
|
import type { SiteConfig } from '../config'
|
|
|
|
import type { SiteConfig } from '../config'
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
EXTERNAL_URL_RE,
|
|
|
|
EXTERNAL_URL_RE,
|
|
|
@ -23,9 +22,9 @@ export async function renderPage(
|
|
|
|
render: (path: string) => Promise<SSGContext>,
|
|
|
|
render: (path: string) => Promise<SSGContext>,
|
|
|
|
config: SiteConfig,
|
|
|
|
config: SiteConfig,
|
|
|
|
page: string, // foo.md
|
|
|
|
page: string, // foo.md
|
|
|
|
result: RollupOutput | null,
|
|
|
|
result: Rollup.RollupOutput | null,
|
|
|
|
appChunk: OutputChunk | null,
|
|
|
|
appChunk: Rollup.OutputChunk | null,
|
|
|
|
cssChunk: OutputAsset | null,
|
|
|
|
cssChunk: Rollup.OutputAsset | null,
|
|
|
|
assets: string[],
|
|
|
|
assets: string[],
|
|
|
|
pageToHashMap: Record<string, string>,
|
|
|
|
pageToHashMap: Record<string, string>,
|
|
|
|
metadataScript: { html: string; inHead: boolean },
|
|
|
|
metadataScript: { html: string; inHead: boolean },
|
|
|
@ -137,7 +136,7 @@ export async function renderPage(
|
|
|
|
(chunk) =>
|
|
|
|
(chunk) =>
|
|
|
|
chunk.type === 'chunk' &&
|
|
|
|
chunk.type === 'chunk' &&
|
|
|
|
chunk.facadeModuleId === slash(path.join(config.srcDir, page))
|
|
|
|
chunk.facadeModuleId === slash(path.join(config.srcDir, page))
|
|
|
|
) as OutputChunk
|
|
|
|
) as Rollup.OutputChunk
|
|
|
|
if (matchingChunk) {
|
|
|
|
if (matchingChunk) {
|
|
|
|
if (!matchingChunk.code.includes('import')) {
|
|
|
|
if (!matchingChunk.code.includes('import')) {
|
|
|
|
inlinedScript = `<script type="module">${matchingChunk.code}</script>`
|
|
|
|
inlinedScript = `<script type="module">${matchingChunk.code}</script>`
|
|
|
@ -198,8 +197,8 @@ export async function renderPage(
|
|
|
|
function resolvePageImports(
|
|
|
|
function resolvePageImports(
|
|
|
|
config: SiteConfig,
|
|
|
|
config: SiteConfig,
|
|
|
|
page: string,
|
|
|
|
page: string,
|
|
|
|
result: RollupOutput,
|
|
|
|
result: Rollup.RollupOutput,
|
|
|
|
appChunk: OutputChunk
|
|
|
|
appChunk: Rollup.OutputChunk
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
page = config.rewrites.inv[page] || page
|
|
|
|
page = config.rewrites.inv[page] || page
|
|
|
|
// find the page's js chunk and inject script tags for its imports so that
|
|
|
|
// find the page's js chunk and inject script tags for its imports so that
|
|
|
@ -214,7 +213,7 @@ function resolvePageImports(
|
|
|
|
srcPath = normalizePath(srcPath)
|
|
|
|
srcPath = normalizePath(srcPath)
|
|
|
|
const pageChunk = result.output.find(
|
|
|
|
const pageChunk = result.output.find(
|
|
|
|
(chunk) => chunk.type === 'chunk' && chunk.facadeModuleId === srcPath
|
|
|
|
(chunk) => chunk.type === 'chunk' && chunk.facadeModuleId === srcPath
|
|
|
|
) as OutputChunk
|
|
|
|
) as Rollup.OutputChunk
|
|
|
|
return [
|
|
|
|
return [
|
|
|
|
...appChunk.imports,
|
|
|
|
...appChunk.imports,
|
|
|
|
...appChunk.dynamicImports,
|
|
|
|
...appChunk.dynamicImports,
|
|
|
|