Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): support cacheDir #1355

Merged
merged 4 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/config/app-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ export default {
}
```

## cacheDir

- Type: `string`
- Default: `./.vitepress/cache`

The directory for cache files, relative to project root (`docs` folder if you're running `vitepress build docs`). See also: [cacheDir](https://vitejs.dev/config/shared-options.html#cachedir).

```ts
export default {
outDir: './.vitepress/.vite'
}
```

## srcDir

- Type: `string`
Expand Down
1 change: 1 addition & 0 deletions src/node/build/buildMPAClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function buildMPAClient(

return build({
root: config.srcDir,
cacheDir: config.cacheDir,
base: config.site.base,
logLevel: 'warn',
build: {
Expand Down
1 change: 1 addition & 0 deletions src/node/build/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function bundle(

const resolveViteConfig = async (ssr: boolean): Promise<ViteUserConfig> => ({
root: config.srcDir,
cacheDir: config.cacheDir,
base: config.site.base,
logLevel: 'warn',
plugins: await createVitePressPlugin(
Expand Down
6 changes: 6 additions & 0 deletions src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface UserConfig<ThemeConfig = any> {
srcDir?: string
srcExclude?: string[]
outDir?: string
cacheDir?: string
shouldPreload?: (link: string, page: string) => boolean

/**
Expand Down Expand Up @@ -165,6 +166,7 @@ export interface SiteConfig<ThemeConfig = any>
configDeps: string[]
themeDir: string
outDir: string
cacheDir: string
tempDir: string
pages: string[]
}
Expand Down Expand Up @@ -203,6 +205,9 @@ export async function resolveConfig(
const outDir = userConfig.outDir
? path.resolve(root, userConfig.outDir)
: resolve(root, 'dist')
const cacheDir = userConfig.cacheDir
? path.resolve(root, userConfig.cacheDir)
: resolve(root, 'cache')

// resolve theme path
const userThemeDir = resolve(root, 'theme')
Expand Down Expand Up @@ -232,6 +237,7 @@ export async function resolveConfig(
configPath,
configDeps,
outDir,
cacheDir,
tempDir: resolve(root, '.temp'),
markdown: userConfig.markdown,
lastUpdated: userConfig.lastUpdated,
Expand Down
1 change: 1 addition & 0 deletions src/node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function createServer(
return createViteServer({
root: config.srcDir,
base: config.site.base,
cacheDir: config.cacheDir,
// logLevel: 'warn',
plugins: await createVitePressPlugin(config, false, {}, {}, recreateServer),
server: serverOptions
Expand Down