|
|
@ -13,10 +13,20 @@ import { APP_PATH } from '../alias'
|
|
|
|
import { createVitePressPlugin } from '../plugin'
|
|
|
|
import { createVitePressPlugin } from '../plugin'
|
|
|
|
import { sanitizeFileName } from '../shared'
|
|
|
|
import { sanitizeFileName } from '../shared'
|
|
|
|
import { buildMPAClient } from './buildMPAClient'
|
|
|
|
import { buildMPAClient } from './buildMPAClient'
|
|
|
|
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
|
|
|
import { normalizePath } from 'vite'
|
|
|
|
|
|
|
|
|
|
|
|
export const okMark = '\x1b[32m✓\x1b[0m'
|
|
|
|
export const okMark = '\x1b[32m✓\x1b[0m'
|
|
|
|
export const failMark = '\x1b[31m✖\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.
|
|
|
|
// bundles the VitePress app for both client AND server.
|
|
|
|
export async function bundle(
|
|
|
|
export async function bundle(
|
|
|
|
config: SiteConfig,
|
|
|
|
config: SiteConfig,
|
|
|
@ -100,6 +110,13 @@ export async function bundle(
|
|
|
|
: 'assets/chunks/[name].[hash].js'
|
|
|
|
: 'assets/chunks/[name].[hash].js'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
manualChunks(id, ctx) {
|
|
|
|
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
|
|
|
|
// move known framework code into a stable chunk so that
|
|
|
|
// custom theme changes do not invalidate hash for all pages
|
|
|
|
// custom theme changes do not invalidate hash for all pages
|
|
|
|
if (id.includes('plugin-vue:export-helper')) {
|
|
|
|
if (id.includes('plugin-vue:export-helper')) {
|
|
|
@ -108,7 +125,7 @@ export async function bundle(
|
|
|
|
if (
|
|
|
|
if (
|
|
|
|
isEagerChunk(id, ctx.getModuleInfo) &&
|
|
|
|
isEagerChunk(id, ctx.getModuleInfo) &&
|
|
|
|
(/@vue\/(runtime|shared|reactivity)/.test(id) ||
|
|
|
|
(/@vue\/(runtime|shared|reactivity)/.test(id) ||
|
|
|
|
/vitepress\/dist\/client/.test(id))
|
|
|
|
id.includes(clientDir))
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return 'framework'
|
|
|
|
return 'framework'
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -174,7 +191,7 @@ function isEagerChunk(id: string, getModuleInfo: GetModuleInfo) {
|
|
|
|
!/\.css($|\\?)/.test(id) &&
|
|
|
|
!/\.css($|\\?)/.test(id) &&
|
|
|
|
staticImportedByEntry(id, getModuleInfo, cache)
|
|
|
|
staticImportedByEntry(id, getModuleInfo, cache)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
return 'vendor'
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|