|
|
|
@ -13,10 +13,20 @@ import { APP_PATH } from '../alias'
|
|
|
|
|
import { createVitePressPlugin } from '../plugin'
|
|
|
|
|
import { sanitizeFileName } from '../shared'
|
|
|
|
|
import { buildMPAClient } from './buildMPAClient'
|
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
import { normalizePath } from 'vite'
|
|
|
|
|
|
|
|
|
|
export const okMark = '\x1b[32m✓\x1b[0m'
|
|
|
|
|
export const failMark = '\x1b[31m✖\x1b[0m'
|
|
|
|
|
|
|
|
|
|
// A list of default theme components that should only be loaded on demand.
|
|
|
|
|
const lazyDefaultThemeComponentsRE =
|
|
|
|
|
/VP(HomeSponsors|DocAsideSponsors|TeamPage|TeamMembers|AlgoliaSearch|CarbonAds|DocAsideCarbonAds)/
|
|
|
|
|
|
|
|
|
|
const clientDir = normalizePath(
|
|
|
|
|
path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../client')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// bundles the VitePress app for both client AND server.
|
|
|
|
|
export async function bundle(
|
|
|
|
|
config: SiteConfig,
|
|
|
|
@ -100,6 +110,13 @@ export async function bundle(
|
|
|
|
|
: 'assets/chunks/[name].[hash].js'
|
|
|
|
|
},
|
|
|
|
|
manualChunks(id, ctx) {
|
|
|
|
|
// optimize default theme chunking
|
|
|
|
|
if (
|
|
|
|
|
id.includes(`${clientDir}/theme-default`) &&
|
|
|
|
|
!lazyDefaultThemeComponentsRE.test(id)
|
|
|
|
|
) {
|
|
|
|
|
return 'theme'
|
|
|
|
|
}
|
|
|
|
|
// move known framework code into a stable chunk so that
|
|
|
|
|
// custom theme changes do not invalidate hash for all pages
|
|
|
|
|
if (id.includes('plugin-vue:export-helper')) {
|
|
|
|
@ -108,7 +125,7 @@ export async function bundle(
|
|
|
|
|
if (
|
|
|
|
|
isEagerChunk(id, ctx.getModuleInfo) &&
|
|
|
|
|
(/@vue\/(runtime|shared|reactivity)/.test(id) ||
|
|
|
|
|
/vitepress\/dist\/client/.test(id))
|
|
|
|
|
id.includes(clientDir))
|
|
|
|
|
) {
|
|
|
|
|
return 'framework'
|
|
|
|
|
}
|
|
|
|
@ -174,7 +191,7 @@ function isEagerChunk(id: string, getModuleInfo: GetModuleInfo) {
|
|
|
|
|
!/\.css($|\\?)/.test(id) &&
|
|
|
|
|
staticImportedByEntry(id, getModuleInfo, cache)
|
|
|
|
|
) {
|
|
|
|
|
return 'vendor'
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|