mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
feat(schema,vite): allow $client
and $server
vite env overrides (#22302)
This commit is contained in:
parent
4aadfac631
commit
e2a6ad353d
@ -10,7 +10,7 @@ export default defineUntypedSchema({
|
||||
* See https://vitejs.dev/config for more information.
|
||||
* Please note that not all vite options are supported in Nuxt.
|
||||
*
|
||||
* @type {typeof import('../src/types/config').ViteConfig}
|
||||
* @type {typeof import('../src/types/config').ViteConfig & { $client?: typeof import('../src/types/config').ViteConfig, $server?: typeof import('../src/types/config').ViteConfig }}
|
||||
*/
|
||||
vite: {
|
||||
root: {
|
||||
|
@ -20,7 +20,7 @@ import { viteNodePlugin } from './vite-node'
|
||||
import { createViteLogger } from './utils/logger'
|
||||
|
||||
export async function buildClient (ctx: ViteBuildContext) {
|
||||
const clientConfig: ViteConfig = vite.mergeConfig(ctx.config, {
|
||||
const clientConfig: ViteConfig = vite.mergeConfig(ctx.config, vite.mergeConfig({
|
||||
configFile: false,
|
||||
base: ctx.nuxt.options.dev
|
||||
? joinURL(ctx.nuxt.options.app.baseURL.replace(/^\.\//, '/') || '/', ctx.nuxt.options.app.buildAssetsDir)
|
||||
@ -82,7 +82,7 @@ export async function buildClient (ctx: ViteBuildContext) {
|
||||
server: {
|
||||
middlewareMode: true
|
||||
}
|
||||
} satisfies vite.InlineConfig)
|
||||
} satisfies vite.InlineConfig, ctx.nuxt.options.vite.$client || {}))
|
||||
|
||||
clientConfig.customLogger = createViteLogger(clientConfig)
|
||||
|
||||
|
@ -16,7 +16,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
const helper = ctx.nuxt.options.nitro.imports !== false ? '' : 'globalThis.'
|
||||
const entry = ctx.nuxt.options.ssr ? ctx.entry : await resolvePath(resolve(ctx.nuxt.options.appDir, 'entry-spa'))
|
||||
const nitroDependencies = await tryResolveModule('nitropack/package.json', ctx.nuxt.options.modulesDir).then(r => import(r!)).then(r => Object.keys(r.dependencies || {})).catch(() => [])
|
||||
const serverConfig: ViteConfig = vite.mergeConfig(ctx.config, {
|
||||
const serverConfig: ViteConfig = vite.mergeConfig(ctx.config, vite.mergeConfig({
|
||||
configFile: false,
|
||||
base: ctx.nuxt.options.dev
|
||||
? joinURL(ctx.nuxt.options.app.baseURL.replace(/^\.\//, '/') || '/', ctx.nuxt.options.app.buildAssetsDir)
|
||||
@ -100,7 +100,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
||||
functions: ['defineComponent', 'defineAsyncComponent', 'defineNuxtLink', 'createClientOnly', 'defineNuxtPlugin', 'defineNuxtRouteMiddleware', 'defineNuxtComponent', 'useRuntimeConfig']
|
||||
})
|
||||
]
|
||||
} satisfies vite.InlineConfig)
|
||||
} satisfies vite.InlineConfig, ctx.nuxt.options.vite.$server || {}))
|
||||
|
||||
serverConfig.customLogger = createViteLogger(serverConfig)
|
||||
|
||||
|
@ -56,6 +56,8 @@ export async function bundle (nuxt: Nuxt) {
|
||||
allowDirs = allowDirs.filter(d => !d.startsWith(dir) || d === dir)
|
||||
}
|
||||
|
||||
const { $client, $server, ...viteConfig } = nuxt.options.vite
|
||||
|
||||
const ctx: ViteBuildContext = {
|
||||
nuxt,
|
||||
entry,
|
||||
@ -121,7 +123,7 @@ export async function bundle (nuxt: Nuxt) {
|
||||
}
|
||||
}
|
||||
} satisfies ViteConfig,
|
||||
nuxt.options.vite
|
||||
viteConfig
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user