Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(vite): use replace for typeof replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 10, 2022
1 parent 756fed1 commit bc7c929
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/vite/src/server.ts
Expand Up @@ -6,6 +6,7 @@ import { logger, resolveModule } from '@nuxt/kit'
import fse from 'fs-extra'
import { debounce } from 'perfect-debounce'
import { withoutTrailingSlash } from 'ufo'
import replace from '@rollup/plugin-replace'
import { ViteBuildContext, ViteOptions } from './vite'
import { wpfs } from './utils/wpfs'
import { cacheDirPlugin } from './plugins/cache-dir'
Expand All @@ -20,12 +21,7 @@ export async function buildServer (ctx: ViteBuildContext) {
const serverConfig: vite.InlineConfig = vite.mergeConfig(ctx.config, {
define: {
'process.server': true,
'process.client': false,
'typeof window': '"undefined"',
'typeof document': '"undefined"',
'typeof navigator': '"undefined"',
'typeof location': '"undefined"',
'typeof XMLHttpRequest': '"undefined"'
'process.client': false
},
resolve: {
alias: {
Expand Down Expand Up @@ -81,6 +77,14 @@ export async function buildServer (ctx: ViteBuildContext) {
cacheDirPlugin(ctx.nuxt.options.rootDir, 'server'),
RelativeAssetPlugin(),
vuePlugin(ctx.config.vue),
replace({
'typeof window': '"undefined"',
'typeof document': '"undefined"',
'typeof navigator': '"undefined"',
'typeof location': '"undefined"',
'typeof XMLHttpRequest': '"undefined"',
preventAssignment: true
}),
viteJsxPlugin()
]
} as ViteOptions)
Expand Down

0 comments on commit bc7c929

Please sign in to comment.