Skip to content

Commit f004d30

Browse files
authored
fix: unmock browser environment when it is not needed (#59)
1 parent b0cb9a4 commit f004d30

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/node/build.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC
100100
mode: config.mode,
101101
}))
102102

103+
let unmock = () => {}
103104
if (mock) {
104105
// @ts-expect-error allow js
105-
const { jsdomGlobal }: { jsdomGlobal: () => void } = await import('./jsdomGlobal.mjs')
106-
jsdomGlobal()
106+
const { jsdomGlobal }: { jsdomGlobal: () => () => void } = await import('./jsdomGlobal.mjs')
107+
unmock = jsdomGlobal()
107108
}
108109

109110
// server
@@ -253,6 +254,7 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC
253254

254255
await fs.remove(join(root, '.vite-react-ssg-temp'))
255256

257+
unmock()
256258
const pwaPlugin: { disabled: boolean, generateSW: () => Promise<unknown> } = config.plugins.find(i => i.name === 'vite-plugin-pwa')?.api
257259
if (pwaPlugin && !pwaPlugin.disabled && pwaPlugin.generateSW) {
258260
buildLog('Regenerate PWA...')

0 commit comments

Comments
 (0)