Skip to content

Commit 5ea73d3

Browse files
fix: resolve outDir configuration timing issue in build process
- Move outDir initialization to use configResolved hook instead of early assignment - Add PluginOption import to support custom plugin configuration - Ensures outDir reflects final resolved configuration after all plugins have processed
1 parent 2ae54e3 commit 5ea73d3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/node/build.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import type { InlineConfig } from 'vite'
2+
import type { InlineConfig, PluginOption } from 'vite'
33
import type { RouteRecord, ViteReactSSGContext, ViteReactSSGOptions } from '../types'
44
import { createRequire } from 'node:module'
55
import { dirname, isAbsolute, join, parse } from 'node:path'
@@ -45,8 +45,7 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC
4545
const root = config.root || cwd
4646
const hash = Math.random().toString(36).substring(2, 12)
4747
const ssgOut = join(root, '.vite-react-ssg-temp', hash)
48-
const outDir = config.build.outDir || 'dist'
49-
const out = isAbsolute(outDir) ? outDir : join(root, outDir)
48+
let outDir = config.build.outDir || 'dist'
5049
const configBase = config.base
5150

5251
const mergedOptions = Object.assign({}, config.ssgOptions || {}, ssgOptions)
@@ -99,6 +98,12 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC
9998
},
10099
customLogger: clientLogger,
101100
mode: config.mode,
101+
plugins: [{
102+
name: 'vite-react-ssg:get-oup-dir',
103+
configResolved(resolvedConfig) {
104+
outDir = resolvedConfig.build.outDir || 'dist'
105+
},
106+
} as PluginOption],
102107
}))
103108

104109
let unmock = () => {}
@@ -173,6 +178,7 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC
173178
if (beasties)
174179
console.log(`${gray('[vite-react-ssg]')} ${blue('Critical CSS generation enabled via `beasties`')}`)
175180

181+
const out = isAbsolute(outDir) ? outDir : join(root, outDir)
176182
const ssrManifest: SSRManifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, 'ssr-manifest.json'), 'utf-8'))
177183
const manifest: Manifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, 'manifest.json'), 'utf-8'))
178184
let indexHTML = await fs.readFile(join(out, htmlEntry), 'utf-8')

0 commit comments

Comments
 (0)