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,