mirror of https://github.com/vuejs/vitepress
parent
b94b163a3a
commit
e0b69973f8
@ -0,0 +1,45 @@
|
||||
import { build } from 'vite'
|
||||
import { SiteConfig } from '..'
|
||||
|
||||
const virtualEntry = 'client.js'
|
||||
|
||||
export async function buildMPAClient(
|
||||
js: Record<string, string>,
|
||||
config: SiteConfig
|
||||
) {
|
||||
const files = Object.keys(js)
|
||||
const themeFiles = files.filter((f) => !f.endsWith('.md'))
|
||||
const pages = files.filter((f) => f.endsWith('.md'))
|
||||
|
||||
return build({
|
||||
root: config.srcDir,
|
||||
base: config.site.base,
|
||||
logLevel: 'warn',
|
||||
build: {
|
||||
emptyOutDir: false,
|
||||
outDir: config.outDir,
|
||||
rollupOptions: {
|
||||
input: [virtualEntry, ...pages]
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
{
|
||||
name: 'vitepress-mpa-client',
|
||||
resolveId(id) {
|
||||
if (id === virtualEntry) {
|
||||
return id
|
||||
}
|
||||
},
|
||||
load(id) {
|
||||
if (id === virtualEntry) {
|
||||
return themeFiles
|
||||
.map((file) => `import ${JSON.stringify(file)}`)
|
||||
.join('\n')
|
||||
} else if (id in js) {
|
||||
return js[id]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
Loading…
Reference in new issue