Skip to content

Commit f899764

Browse files
authored
feat(build): support cacheDir (#1355)
1 parent 6b4b31d commit f899764

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

docs/config/app-configs.md

+13
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ export default {
198198
}
199199
```
200200

201+
## cacheDir
202+
203+
- Type: `string`
204+
- Default: `./.vitepress/cache`
205+
206+
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).
207+
208+
```ts
209+
export default {
210+
outDir: './.vitepress/.vite'
211+
}
212+
```
213+
201214
## srcDir
202215

203216
- Type: `string`

src/node/build/buildMPAClient.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export async function buildMPAClient(
1414

1515
return build({
1616
root: config.srcDir,
17+
cacheDir: config.cacheDir,
1718
base: config.site.base,
1819
logLevel: 'warn',
1920
build: {

src/node/build/bundle.ts

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export async function bundle(
4141

4242
const resolveViteConfig = async (ssr: boolean): Promise<ViteUserConfig> => ({
4343
root: config.srcDir,
44+
cacheDir: config.cacheDir,
4445
base: config.site.base,
4546
logLevel: 'warn',
4647
plugins: await createVitePressPlugin(

src/node/config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface UserConfig<ThemeConfig = any> {
5353
srcDir?: string
5454
srcExclude?: string[]
5555
outDir?: string
56+
cacheDir?: string
5657
shouldPreload?: (link: string, page: string) => boolean
5758

5859
/**
@@ -165,6 +166,7 @@ export interface SiteConfig<ThemeConfig = any>
165166
configDeps: string[]
166167
themeDir: string
167168
outDir: string
169+
cacheDir: string
168170
tempDir: string
169171
pages: string[]
170172
}
@@ -203,6 +205,9 @@ export async function resolveConfig(
203205
const outDir = userConfig.outDir
204206
? path.resolve(root, userConfig.outDir)
205207
: resolve(root, 'dist')
208+
const cacheDir = userConfig.cacheDir
209+
? path.resolve(root, userConfig.cacheDir)
210+
: resolve(root, 'cache')
206211

207212
// resolve theme path
208213
const userThemeDir = resolve(root, 'theme')
@@ -232,6 +237,7 @@ export async function resolveConfig(
232237
configPath,
233238
configDeps,
234239
outDir,
240+
cacheDir,
235241
tempDir: resolve(root, '.temp'),
236242
markdown: userConfig.markdown,
237243
lastUpdated: userConfig.lastUpdated,

src/node/server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export async function createServer(
2020
return createViteServer({
2121
root: config.srcDir,
2222
base: config.site.base,
23+
cacheDir: config.cacheDir,
2324
// logLevel: 'warn',
2425
plugins: await createVitePressPlugin(config, false, {}, {}, recreateServer),
2526
server: serverOptions

0 commit comments

Comments
 (0)