basic build

pull/1/head
Evan You 4 years ago
parent 4636a23a15
commit 89545b5270

@ -1,8 +1,48 @@
import path from 'path'
import { APP_PATH, createResolver } from '../utils/pathResolver'
import { build, BuildOptions } from 'vite'
import { resolveConfig } from '../resolveConfig'
import { Plugin } from 'rollup'
export async function buildClient(options: BuildOptions) {
const root = options.root || process.cwd()
const config = await resolveConfig(root)
const resolver = createResolver(config.themePath)
const {
resolvers = [],
srcRoots = [],
rollupInputOptions = {},
rollupOutputOptions = {}
} = options
const VitePressPlugin: Plugin = {
name: 'vitepress',
load(id) {
if (id === '/@siteData') {
return `export default ${JSON.stringify(JSON.stringify(config.site))}`
}
}
}
await build({
...options,
cdn: false
cdn: false,
resolvers: [resolver, ...resolvers],
srcRoots: [APP_PATH, config.themePath, ...srcRoots],
indexPath: path.resolve(APP_PATH, 'index.html'),
rollupInputOptions: {
...rollupInputOptions,
input: path.resolve(APP_PATH, 'index.js'),
plugins: [VitePressPlugin, ...(rollupInputOptions.plugins || [])]
},
rollupOutputOptions: {
dir: path.resolve(root, '.vitepress/dist'),
...rollupOutputOptions
},
debug: !!process.env.DEBUG
})
// console.log(output)
// console.log(css)
}

@ -122,7 +122,7 @@ function createVitePressPlugin(config: ResolvedConfig): Plugin {
// serve our index.html after vite history fallback
if (ctx.url.endsWith('.html')) {
await cachedRead(ctx, path.join(APP_PATH, 'index-dev.html'))
await cachedRead(ctx, path.join(APP_PATH, 'index.html'))
}
})
}

@ -20,6 +20,9 @@ export function createResolver(themePath: string): Resolver {
if (publicPath.startsWith('/@theme')) {
return path.join(themePath, publicPath.replace(/^\/@theme\/?/, ''))
}
if (publicPath === SITE_DATA_REQUEST_PATH) {
return SITE_DATA_REQUEST_PATH
}
},
fileToRequest(filePath) {
if (filePath.startsWith(APP_PATH)) {

Loading…
Cancel
Save