Skip to content

Commit

Permalink
fix(vite): use rollup replace plugin for typeof optimisations (#23903)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Nov 14, 2023
1 parent 9288e6f commit 86693c1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/vite/src/server.ts
Expand Up @@ -5,6 +5,7 @@ import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
import { logger, resolvePath, tryResolveModule } from '@nuxt/kit'
import { joinURL, withTrailingSlash, withoutLeadingSlash } from 'ufo'
import type { ViteConfig } from '@nuxt/schema'
import replace from '@rollup/plugin-replace'
import type { ViteBuildContext } from './vite'
import { createViteLogger } from './utils/logger'
import { initViteNodeServer } from './vite-node'
Expand Down Expand Up @@ -43,12 +44,7 @@ export async function buildServer (ctx: ViteBuildContext) {
'process.browser': false,
'import.meta.server': true,
'import.meta.client': false,
'import.meta.browser': false,
'typeof window': '"undefined"',
'typeof document': '"undefined"',
'typeof navigator': '"undefined"',
'typeof location': '"undefined"',
'typeof XMLHttpRequest': '"undefined"'
'import.meta.browser': false
},
optimizeDeps: {
entries: ctx.nuxt.options.ssr ? [ctx.entry] : []
Expand Down Expand Up @@ -100,7 +96,18 @@ export async function buildServer (ctx: ViteBuildContext) {
preTransformRequests: false,
hmr: false
},
plugins: []
plugins: [
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 || {}))

if (!ctx.nuxt.options.dev) {
Expand Down

0 comments on commit 86693c1

Please sign in to comment.