mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(vite): set different cache dirs for client/server (#20276)
This commit is contained in:
parent
53db8125f1
commit
b602b66a8e
@ -10,7 +10,6 @@ import { joinURL, withoutLeadingSlash } from 'ufo'
|
|||||||
import { defu } from 'defu'
|
import { defu } from 'defu'
|
||||||
import { defineEventHandler } from 'h3'
|
import { defineEventHandler } from 'h3'
|
||||||
import type { ViteConfig } from '@nuxt/schema'
|
import type { ViteConfig } from '@nuxt/schema'
|
||||||
import { cacheDirPlugin } from './plugins/cache-dir'
|
|
||||||
import { chunkErrorPlugin } from './plugins/chunk-error'
|
import { chunkErrorPlugin } from './plugins/chunk-error'
|
||||||
import type { ViteBuildContext } from './vite'
|
import type { ViteBuildContext } from './vite'
|
||||||
import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
|
import { devStyleSSRPlugin } from './plugins/dev-ssr-css'
|
||||||
@ -51,6 +50,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
},
|
},
|
||||||
dedupe: ['vue']
|
dedupe: ['vue']
|
||||||
},
|
},
|
||||||
|
cacheDir: resolve(ctx.nuxt.options.rootDir, 'node_modules/.cache/vite', 'client'),
|
||||||
build: {
|
build: {
|
||||||
sourcemap: ctx.nuxt.options.sourcemap.client ? ctx.config.build?.sourcemap ?? true : false,
|
sourcemap: ctx.nuxt.options.sourcemap.client ? ctx.config.build?.sourcemap ?? true : false,
|
||||||
manifest: true,
|
manifest: true,
|
||||||
@ -60,7 +60,6 @@ export async function buildClient (ctx: ViteBuildContext) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
cacheDirPlugin(ctx.nuxt.options.rootDir, 'client'),
|
|
||||||
devStyleSSRPlugin({
|
devStyleSSRPlugin({
|
||||||
srcDir: ctx.nuxt.options.srcDir,
|
srcDir: ctx.nuxt.options.srcDir,
|
||||||
buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir)
|
buildAssetsURL: joinURL(ctx.nuxt.options.app.baseURL, ctx.nuxt.options.app.buildAssetsDir)
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
import { resolve } from 'pathe'
|
|
||||||
import type { Plugin } from 'vite'
|
|
||||||
|
|
||||||
export function cacheDirPlugin (rootDir: string, name: string) {
|
|
||||||
const optimizeCacheDir = resolve(rootDir, 'node_modules/.cache/vite', name)
|
|
||||||
return <Plugin> {
|
|
||||||
name: 'nuxt:cache-dir',
|
|
||||||
configResolved (resolvedConfig) {
|
|
||||||
// @ts-expect-error
|
|
||||||
resolvedConfig.optimizeCacheDir = optimizeCacheDir
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ import { joinURL, withTrailingSlash, withoutLeadingSlash } from 'ufo'
|
|||||||
import type { ViteConfig } from '@nuxt/schema'
|
import type { ViteConfig } from '@nuxt/schema'
|
||||||
import type { ViteBuildContext } from './vite'
|
import type { ViteBuildContext } from './vite'
|
||||||
import { createViteLogger } from './utils/logger'
|
import { createViteLogger } from './utils/logger'
|
||||||
import { cacheDirPlugin } from './plugins/cache-dir'
|
|
||||||
import { initViteNodeServer } from './vite-node'
|
import { initViteNodeServer } from './vite-node'
|
||||||
import { ssrStylesPlugin } from './plugins/ssr-styles'
|
import { ssrStylesPlugin } from './plugins/ssr-styles'
|
||||||
import { pureAnnotationsPlugin } from './plugins/pure-annotations'
|
import { pureAnnotationsPlugin } from './plugins/pure-annotations'
|
||||||
@ -82,6 +81,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
/(nuxt|nuxt3)\/(dist|src|app)/
|
/(nuxt|nuxt3)\/(dist|src|app)/
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
cacheDir: resolve(ctx.nuxt.options.rootDir, 'node_modules/.cache/vite', 'server'),
|
||||||
build: {
|
build: {
|
||||||
sourcemap: ctx.nuxt.options.sourcemap.server ? ctx.config.build?.sourcemap ?? true : false,
|
sourcemap: ctx.nuxt.options.sourcemap.server ? ctx.config.build?.sourcemap ?? true : false,
|
||||||
outDir: resolve(ctx.nuxt.options.buildDir, 'dist/server'),
|
outDir: resolve(ctx.nuxt.options.buildDir, 'dist/server'),
|
||||||
@ -110,7 +110,6 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
hmr: false
|
hmr: false
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
cacheDirPlugin(ctx.nuxt.options.rootDir, 'server'),
|
|
||||||
pureAnnotationsPlugin.vite({
|
pureAnnotationsPlugin.vite({
|
||||||
sourcemap: ctx.nuxt.options.sourcemap.server,
|
sourcemap: ctx.nuxt.options.sourcemap.server,
|
||||||
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig']
|
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig']
|
||||||
|
Loading…
Reference in New Issue
Block a user