|
1 | 1 | /* eslint-disable no-console */ |
2 | | -import type { InlineConfig } from 'vite' |
| 2 | +import type { InlineConfig, PluginOption } from 'vite' |
3 | 3 | import type { RouteRecord, ViteReactSSGContext, ViteReactSSGOptions } from '../types' |
4 | 4 | import { createRequire } from 'node:module' |
5 | 5 | import { dirname, isAbsolute, join, parse } from 'node:path' |
@@ -45,8 +45,7 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC |
45 | 45 | const root = config.root || cwd |
46 | 46 | const hash = Math.random().toString(36).substring(2, 12) |
47 | 47 | 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' |
50 | 49 | const configBase = config.base |
51 | 50 |
|
52 | 51 | const mergedOptions = Object.assign({}, config.ssgOptions || {}, ssgOptions) |
@@ -99,6 +98,12 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC |
99 | 98 | }, |
100 | 99 | customLogger: clientLogger, |
101 | 100 | 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], |
102 | 107 | })) |
103 | 108 |
|
104 | 109 | let unmock = () => {} |
@@ -173,6 +178,7 @@ export async function build(ssgOptions: Partial<ViteReactSSGOptions> = {}, viteC |
173 | 178 | if (beasties) |
174 | 179 | console.log(`${gray('[vite-react-ssg]')} ${blue('Critical CSS generation enabled via `beasties`')}`) |
175 | 180 |
|
| 181 | + const out = isAbsolute(outDir) ? outDir : join(root, outDir) |
176 | 182 | const ssrManifest: SSRManifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, 'ssr-manifest.json'), 'utf-8')) |
177 | 183 | const manifest: Manifest = JSON.parse(await fs.readFile(join(out, ...dotVitedir, 'manifest.json'), 'utf-8')) |
178 | 184 | let indexHTML = await fs.readFile(join(out, htmlEntry), 'utf-8') |
|
0 commit comments