bundle both client and ssr

pull/1/head
Evan You 5 years ago
parent 220622557f
commit b94a0865b0

@ -58,6 +58,7 @@ const App = {
}
}
// TODO use createSSRApp in production
const app = createApp(App)
app.component('Content', Content)

@ -1,6 +1,11 @@
import { buildClient } from './buildClient'
import { BuildOptions } from 'vite'
import { bundle } from './bundle'
import { BuildOptions as ViteBuildOptions } from 'vite'
export type BuildOptions = Pick<
ViteBuildOptions,
'root' | 'rollupInputOptions' | 'rollupOutputOptions'
>
export async function build(options: BuildOptions = {}) {
await buildClient(options)
await bundle(options)
}

@ -3,20 +3,20 @@ import globby from 'globby'
import slash from 'slash'
import { promises as fs } from 'fs'
import { APP_PATH, createResolver } from '../utils/pathResolver'
import { build, BuildOptions } from 'vite'
import { build } from 'vite'
import { BuildOptions } from './build'
import { resolveConfig } from '../resolveConfig'
import { Plugin } from 'rollup'
import { createMarkdownToVueRenderFn } from '../markdownToVue'
export async function buildClient(options: BuildOptions) {
// bundles the VitePress app for both client AND server.
export async function bundle(options: BuildOptions) {
const root = options.root || process.cwd()
const config = await resolveConfig(root)
const resolver = createResolver(config.themePath)
const markdownToVue = createMarkdownToVueRenderFn(root)
const {
resolvers = [],
srcRoots = [],
rollupInputOptions = {},
rollupOutputOptions = {}
} = options
@ -83,18 +83,27 @@ export async function buildClient(options: BuildOptions) {
await build({
...options,
cdn: false,
resolvers: [resolver, ...resolvers],
srcRoots: [APP_PATH, config.themePath, ...srcRoots],
silent: true,
resolvers: [resolver],
srcRoots: [APP_PATH, config.themePath],
cssFileName: 'css/style.css',
rollupInputOptions: {
...rollupInputOptions,
input: [path.resolve(APP_PATH, 'index.js'), ...pages],
plugins: [VitePressPlugin, ...(rollupInputOptions.plugins || [])]
},
rollupOutputOptions: {
rollupOutputOptions: [
{
dir: path.resolve(root, '.vitepress/dist'),
...rollupOutputOptions
},
cssFileName: 'css/style.css',
{
dir: path.resolve(root, '.vitepress/temp'),
...rollupOutputOptions,
format: 'cjs',
exports: 'named'
}
],
debug: !!process.env.DEBUG
})
}

@ -1,4 +1,5 @@
import path from 'path'
import chalk from 'chalk'
import { promises as fs } from 'fs'
import { createResolver } from './utils/pathResolver'
import { Resolver } from 'vite'
@ -61,12 +62,16 @@ export async function resolveSiteData(root: string): Promise<SiteData> {
try {
await fs.stat(configPath)
hasUserConfig = true
debug(`loading user config at ${configPath}`)
} catch (e) {}
// always delete cache first before loading config
delete require.cache[configPath]
const userConfig: UserConfig = hasUserConfig ? require(configPath) : {}
if (hasUserConfig) {
debug(`loaded config at ${chalk.yellow(configPath)}`)
} else {
debug(`no config file found.`)
}
return {
title: userConfig.title || 'VitePress',

Loading…
Cancel
Save