From 88f0b4f420f46de198b0d5a81f11c2b5acc20b4b Mon Sep 17 00:00:00 2001 From: Josh Dean Date: Sat, 15 Jun 2024 14:02:57 -0700 Subject: [PATCH] fix(schema,vite): respect `vite.cacheDir` if defined (#27628) --- packages/schema/src/config/vite.ts | 4 ++++ packages/vite/src/client.ts | 2 +- packages/vite/src/server.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/schema/src/config/vite.ts b/packages/schema/src/config/vite.ts index 663f6d9b8b..a8da7e0cd4 100644 --- a/packages/schema/src/config/vite.ts +++ b/packages/schema/src/config/vite.ts @@ -1,4 +1,5 @@ import { consola } from 'consola' +import { resolve } from 'pathe' import { isTest } from 'std-env' import { withoutLeadingSlash } from 'ufo' import { defineUntypedSchema } from 'untyped' @@ -109,5 +110,8 @@ export default defineUntypedSchema({ }, }, }, + cacheDir: { + $resolve: async (val, get) => val ?? resolve(await get('rootDir') as string, 'node_modules/.cache/vite'), + }, }, }) diff --git a/packages/vite/src/client.ts b/packages/vite/src/client.ts index 607666f933..5ff1679549 100644 --- a/packages/vite/src/client.ts +++ b/packages/vite/src/client.ts @@ -118,7 +118,7 @@ export async function buildClient (ctx: ViteBuildContext) { 'vue', ], }, - cacheDir: resolve(ctx.nuxt.options.rootDir, 'node_modules/.cache/vite', 'client'), + cacheDir: resolve(ctx.nuxt.options.rootDir, ctx.config.cacheDir ?? 'node_modules/.cache/vite', 'client'), build: { sourcemap: ctx.nuxt.options.sourcemap.client ? ctx.config.build?.sourcemap ?? ctx.nuxt.options.sourcemap.client : false, manifest: 'manifest.json', diff --git a/packages/vite/src/server.ts b/packages/vite/src/server.ts index 67919c8b2f..af87239aa2 100644 --- a/packages/vite/src/server.ts +++ b/packages/vite/src/server.ts @@ -71,7 +71,7 @@ export async function buildServer (ctx: ViteBuildContext) { /(nuxt|nuxt3|nuxt-nightly)\/(dist|src|app)/, ], }, - cacheDir: resolve(ctx.nuxt.options.rootDir, 'node_modules/.cache/vite', 'server'), + cacheDir: resolve(ctx.nuxt.options.rootDir, ctx.config.cacheDir ?? 'node_modules/.cache/vite', 'server'), build: { // we'll display this in nitro build output reportCompressedSize: false,