```ts // build.ts import { build as viteBuild } from 'vite'; import { stringifyProcessEnvs } from './envs'; import { commonConfig } from './vite-config'; import type { EnvsRaw, ExtendedOptions } from './types'; export async function build(options: ExtendedOptions) { const { presets } = options; const baseConfig = await commonConfig(options, 'build'); const config = { ...baseConfig, build: { outDir: options.outputDir, emptyOutDir: false, sourcemap: true, }, }; const finalConfig = await presets.apply('viteFinal', config, options); const envsRaw = await presets.apply>('env'); // Stringify env variables after getting `envPrefix` from the final config const envs = stringifyProcessEnvs(envsRaw, finalConfig.envPrefix); // Update `define` finalConfig.define = { ...finalConfig.define, ...envs, }; await viteBuild(finalConfig); } ```