import * as path from 'path' ; import { build as viteBuild } from 'vite' ; import { allowedEnvPrefix as envPrefix , stringifyProcessEnvs } from './envs' ; import { pluginConfig } from './vite-config' ; import type { UserConfig } from 'vite' ; import type { EnvsRaw , ExtendedOptions } from './types' ; export async function build ( options ) { const { presets } = options ; const config = { configFile : false , root : path . resolve ( options . configDir , '..' ) , build : { outDir : options . outputDir , emptyOutDir : false , sourcemap : true , } , envPrefix , define : { } , resolve : { alias : { vue : 'vue/dist/vue.esm-bundler.js' , } , } , plugins : await pluginConfig ( options , 'build' ) , } as UserConfig ; const finalConfig = await presets . apply ( 'viteFinal' , config , options ) ; const envsRaw = await presets . apply < Promise < EnvsRaw > > ( 'env' ) ; const envs = stringifyProcessEnvs ( envsRaw , finalConfig . envPrefix ) ; finalConfig . define = { ... finalConfig . define , ... envs , } ; await viteBuild ( finalConfig ) ; }