mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-19 15:10:58 +00:00
feat(vite): replace browser globals with undefined
on server (#24711)
This commit is contained in:
parent
72c8503236
commit
37a5d35a6d
@ -5,7 +5,6 @@ import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
|||||||
import { logger, resolvePath, tryResolveModule } from '@nuxt/kit'
|
import { logger, resolvePath, tryResolveModule } from '@nuxt/kit'
|
||||||
import { joinURL, withTrailingSlash, withoutLeadingSlash } from 'ufo'
|
import { joinURL, withTrailingSlash, withoutLeadingSlash } from 'ufo'
|
||||||
import type { ViteConfig } from '@nuxt/schema'
|
import type { ViteConfig } from '@nuxt/schema'
|
||||||
import replace from '@rollup/plugin-replace'
|
|
||||||
import type { ViteBuildContext } from './vite'
|
import type { ViteBuildContext } from './vite'
|
||||||
import { createViteLogger } from './utils/logger'
|
import { createViteLogger } from './utils/logger'
|
||||||
import { initViteNodeServer } from './vite-node'
|
import { initViteNodeServer } from './vite-node'
|
||||||
@ -44,7 +43,12 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
'process.browser': false,
|
'process.browser': false,
|
||||||
'import.meta.server': true,
|
'import.meta.server': true,
|
||||||
'import.meta.client': false,
|
'import.meta.client': false,
|
||||||
'import.meta.browser': false
|
'import.meta.browser': false,
|
||||||
|
'window': 'undefined',
|
||||||
|
'document': 'undefined',
|
||||||
|
'navigator': 'undefined',
|
||||||
|
'location': 'undefined',
|
||||||
|
'XMLHttpRequest': 'undefined'
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
optimizeDeps: {
|
||||||
entries: ctx.nuxt.options.ssr ? [ctx.entry] : []
|
entries: ctx.nuxt.options.ssr ? [ctx.entry] : []
|
||||||
@ -96,19 +100,6 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
preTransformRequests: false,
|
preTransformRequests: false,
|
||||||
hmr: false
|
hmr: false
|
||||||
},
|
},
|
||||||
plugins: [
|
|
||||||
// @ts-expect-error types not compatible yet in `@rollup/plugin-replace`
|
|
||||||
replace({
|
|
||||||
values: {
|
|
||||||
'typeof window': '"undefined"',
|
|
||||||
'typeof document': '"undefined"',
|
|
||||||
'typeof navigator': '"undefined"',
|
|
||||||
'typeof location': '"undefined"',
|
|
||||||
'typeof XMLHttpRequest': '"undefined"'
|
|
||||||
},
|
|
||||||
preventAssignment: true
|
|
||||||
})
|
|
||||||
]
|
|
||||||
} satisfies vite.InlineConfig, ctx.nuxt.options.vite.$server || {}))
|
} satisfies vite.InlineConfig, ctx.nuxt.options.vite.$server || {}))
|
||||||
|
|
||||||
if (!ctx.nuxt.options.dev) {
|
if (!ctx.nuxt.options.dev) {
|
||||||
|
Loading…
Reference in New Issue
Block a user