Skip to content

Commit

Permalink
fix: unmock browser environment when it is not needed (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityTwoG authored Jan 19, 2025
1 parent b0cb9a4 commit f004d30
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC
mode: config.mode,
}))

let unmock = () => {}
if (mock) {
// @ts-expect-error allow js
const { jsdomGlobal }: { jsdomGlobal: () => void } = await import('./jsdomGlobal.mjs')
jsdomGlobal()
const { jsdomGlobal }: { jsdomGlobal: () => () => void } = await import('./jsdomGlobal.mjs')
unmock = jsdomGlobal()
}

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

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

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

0 comments on commit f004d30

Please sign in to comment.