Skip to content

Commit

Permalink
feat(build): support cacheDir (#1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 11, 2022
1 parent 6b4b31d commit f899764
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
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

0 comments on commit f899764

Please sign in to comment.