|
|
@ -38,70 +38,70 @@ export async function bundle(
|
|
|
|
// resolve options to pass to vite
|
|
|
|
// resolve options to pass to vite
|
|
|
|
const { rollupOptions } = options
|
|
|
|
const { rollupOptions } = options
|
|
|
|
|
|
|
|
|
|
|
|
const resolveViteConfig = async (ssr: boolean): Promise<ViteUserConfig> => {
|
|
|
|
const resolveViteConfig = async (ssr: boolean): Promise<ViteUserConfig> => ({
|
|
|
|
// use different entry based on ssr or not
|
|
|
|
root: config.srcDir,
|
|
|
|
input['app'] = path.resolve(APP_PATH, ssr ? 'ssr.js' : 'index.js')
|
|
|
|
base: config.site.base,
|
|
|
|
return {
|
|
|
|
logLevel: 'warn',
|
|
|
|
root: config.srcDir,
|
|
|
|
plugins: await createVitePressPlugin(
|
|
|
|
base: config.site.base,
|
|
|
|
config,
|
|
|
|
logLevel: 'warn',
|
|
|
|
ssr,
|
|
|
|
plugins: await createVitePressPlugin(
|
|
|
|
pageToHashMap,
|
|
|
|
config,
|
|
|
|
clientJSMap
|
|
|
|
ssr,
|
|
|
|
),
|
|
|
|
pageToHashMap,
|
|
|
|
ssr: {
|
|
|
|
clientJSMap
|
|
|
|
noExternal: ['vitepress', '@docsearch/css']
|
|
|
|
),
|
|
|
|
},
|
|
|
|
ssr: {
|
|
|
|
build: {
|
|
|
|
noExternal: ['vitepress', '@docsearch/css']
|
|
|
|
...options,
|
|
|
|
},
|
|
|
|
emptyOutDir: true,
|
|
|
|
build: {
|
|
|
|
ssr,
|
|
|
|
...options,
|
|
|
|
outDir: ssr ? config.tempDir : config.outDir,
|
|
|
|
emptyOutDir: true,
|
|
|
|
cssCodeSplit: false,
|
|
|
|
ssr,
|
|
|
|
rollupOptions: {
|
|
|
|
outDir: ssr ? config.tempDir : config.outDir,
|
|
|
|
...rollupOptions,
|
|
|
|
cssCodeSplit: false,
|
|
|
|
input: {
|
|
|
|
rollupOptions: {
|
|
|
|
...input,
|
|
|
|
...rollupOptions,
|
|
|
|
// use different entry based on ssr or not
|
|
|
|
input,
|
|
|
|
app: path.resolve(APP_PATH, ssr ? 'ssr.js' : 'index.js')
|
|
|
|
// important so that each page chunk and the index export things for each
|
|
|
|
|
|
|
|
// other
|
|
|
|
|
|
|
|
preserveEntrySignatures: 'allow-extension',
|
|
|
|
|
|
|
|
output: {
|
|
|
|
|
|
|
|
...rollupOptions?.output,
|
|
|
|
|
|
|
|
...(ssr
|
|
|
|
|
|
|
|
? {
|
|
|
|
|
|
|
|
entryFileNames: `[name].js`,
|
|
|
|
|
|
|
|
chunkFileNames: `[name].[hash].js`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
: {
|
|
|
|
|
|
|
|
chunkFileNames(chunk) {
|
|
|
|
|
|
|
|
// avoid ads chunk being intercepted by adblock
|
|
|
|
|
|
|
|
return /(?:Carbon|BuySell)Ads/.test(chunk.name)
|
|
|
|
|
|
|
|
? `assets/chunks/ui-custom.[hash].js`
|
|
|
|
|
|
|
|
: `assets/chunks/[name].[hash].js`
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
manualChunks(id, ctx) {
|
|
|
|
|
|
|
|
// 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')) {
|
|
|
|
|
|
|
|
return 'framework'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
isEagerChunk(id, ctx) &&
|
|
|
|
|
|
|
|
(/@vue\/(runtime|shared|reactivity)/.test(id) ||
|
|
|
|
|
|
|
|
/vitepress\/dist\/client/.test(id))
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return 'framework'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// minify with esbuild in MPA mode (for CSS)
|
|
|
|
// important so that each page chunk and the index export things for each
|
|
|
|
minify: ssr ? (config.mpa ? 'esbuild' : false) : !process.env.DEBUG
|
|
|
|
// other
|
|
|
|
}
|
|
|
|
preserveEntrySignatures: 'allow-extension',
|
|
|
|
|
|
|
|
output: {
|
|
|
|
|
|
|
|
...rollupOptions?.output,
|
|
|
|
|
|
|
|
...(ssr
|
|
|
|
|
|
|
|
? {
|
|
|
|
|
|
|
|
entryFileNames: `[name].js`,
|
|
|
|
|
|
|
|
chunkFileNames: `[name].[hash].js`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
: {
|
|
|
|
|
|
|
|
chunkFileNames(chunk) {
|
|
|
|
|
|
|
|
// avoid ads chunk being intercepted by adblock
|
|
|
|
|
|
|
|
return /(?:Carbon|BuySell)Ads/.test(chunk.name)
|
|
|
|
|
|
|
|
? `assets/chunks/ui-custom.[hash].js`
|
|
|
|
|
|
|
|
: `assets/chunks/[name].[hash].js`
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
manualChunks(id, ctx) {
|
|
|
|
|
|
|
|
// 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')) {
|
|
|
|
|
|
|
|
return 'framework'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
isEagerChunk(id, ctx) &&
|
|
|
|
|
|
|
|
(/@vue\/(runtime|shared|reactivity)/.test(id) ||
|
|
|
|
|
|
|
|
/vitepress\/dist\/client/.test(id))
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return 'framework'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// minify with esbuild in MPA mode (for CSS)
|
|
|
|
|
|
|
|
minify: ssr ? (config.mpa ? 'esbuild' : false) : !process.env.DEBUG
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
let clientResult: RollupOutput
|
|
|
|
let clientResult: RollupOutput
|
|
|
|
let serverResult: RollupOutput
|
|
|
|
let serverResult: RollupOutput
|
|
|
|