@@ -19,30 +19,29 @@ export async function loadJsConfig(path: string): Promise<object> {
1919 return config as object ;
2020}
2121
22- const VITE_OXFMT_CONFIG_FIELD = "fmt" ;
22+ const VP_OXFMT_CONFIG_FIELD = "fmt" ;
23+ let vitePlusCache = null as typeof import ( "vite-plus" ) | null ;
24+
2325/**
24- * Load a Vite+ config file (`vite.config.ts`) and extract the `.fmt` field.
26+ * Load a Vite+ config file (`vite.config.ts`) via `vite-plus`'s `resolveConfig` and extract the `.fmt` field.
2527 *
2628 * @param path - Absolute path to the Vite config file
2729 * @returns Config object from `.fmt` field, or `null` to signal "skip"
2830 */
2931export async function loadVitePlusConfig ( path : string ) : Promise < object | null > {
30- const config = await importJsConfig ( path , Date . now ( ) ) ;
32+ vitePlusCache ??= await import ( "vite-plus" ) ;
33+ const config = await vitePlusCache . resolveConfig ( { configFile : path } , "build" ) ;
3134
32- // NOTE: Vite configs may export a function via `defineConfig(() => ({ ... }))`,
33- // but we don't know the arguments to call the function.
34- // Treat non-object exports as "no config" and skip for now.
35- if ( ! isObject ( config ) ) return null ;
35+ // NOTE: return `null` if `.fmt` is missing (signals "skip" to Rust side)
36+ if ( VP_OXFMT_CONFIG_FIELD in config === false ) return null ;
3637
37- const fmtConfig = ( config as Record < string , unknown > ) [ VITE_OXFMT_CONFIG_FIELD ] ;
38- // NOTE: return `null` if missing (signals "skip" to Rust side)
39- if ( fmtConfig === undefined ) return null ;
38+ const fmtConfig = config [ VP_OXFMT_CONFIG_FIELD ] ;
4039
4140 if ( ! isObject ( fmtConfig ) ) {
4241 throw new Error (
43- `The \`${ VITE_OXFMT_CONFIG_FIELD } \` field in the default export must be an object.` ,
42+ `The \`${ VP_OXFMT_CONFIG_FIELD } \` field in the default export must be an object.` ,
4443 ) ;
4544 }
4645
47- return fmtConfig ;
46+ return fmtConfig as object ;
4847}
0 commit comments