From 5b2660b181a1d78eac779bd1a3eff4d7048af41d Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 18 Sep 2022 01:14:58 +0800 Subject: [PATCH 1/3] feat: support `cacheDir` --- src/node/build/bundle.ts | 1 + src/node/config.ts | 6 ++++++ src/node/server.ts | 1 + 3 files changed, 8 insertions(+) diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index 1ec51b3707ca..5775afdf9e24 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -40,6 +40,7 @@ export async function bundle( const resolveViteConfig = async (ssr: boolean): Promise => ({ root: config.srcDir, + cacheDir: config.cacheDir, base: config.site.base, logLevel: 'warn', plugins: await createVitePressPlugin( diff --git a/src/node/config.ts b/src/node/config.ts index 8d1f73e1428d..149ce509ce28 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -53,6 +53,7 @@ export interface UserConfig { srcDir?: string srcExclude?: string[] outDir?: string + cacheDir?: string shouldPreload?: (link: string, page: string) => boolean /** @@ -146,6 +147,7 @@ export interface SiteConfig configDeps: string[] themeDir: string outDir: string + cacheDir: string tempDir: string pages: string[] } @@ -184,6 +186,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') @@ -213,6 +218,7 @@ export async function resolveConfig( configPath, configDeps, outDir, + cacheDir, tempDir: resolve(root, '.temp'), markdown: userConfig.markdown, lastUpdated: userConfig.lastUpdated, diff --git a/src/node/server.ts b/src/node/server.ts index 391b0c018593..2c80371a7cf9 100644 --- a/src/node/server.ts +++ b/src/node/server.ts @@ -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 From 4a6c5f5eddb2d1507c0f75e9cbf716afddb75218 Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 18 Sep 2022 01:18:37 +0800 Subject: [PATCH 2/3] docs: add `cacheDir` --- docs/config/app-configs.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/config/app-configs.md b/docs/config/app-configs.md index b29950bf094e..7ec48a38d9bd 100644 --- a/docs/config/app-configs.md +++ b/docs/config/app-configs.md @@ -194,6 +194,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' +} +``` + ## title - Type: `string` From fdca00ddb9ff39d01eb81e409cde0a6db3f77f2b Mon Sep 17 00:00:00 2001 From: Shigma Date: Sun, 18 Sep 2022 01:31:31 +0800 Subject: [PATCH 3/3] chore: add missing `cacheDir` --- src/node/build/buildMPAClient.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node/build/buildMPAClient.ts b/src/node/build/buildMPAClient.ts index ca3c97be055e..c61ee940d0aa 100644 --- a/src/node/build/buildMPAClient.ts +++ b/src/node/build/buildMPAClient.ts @@ -14,6 +14,7 @@ export async function buildMPAClient( return build({ root: config.srcDir, + cacheDir: config.cacheDir, base: config.site.base, logLevel: 'warn', build: {