mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 04:41:07 +08:00
36 lines
961 B
Markdown
36 lines
961 B
Markdown
```ts filename="build.ts" renderer="common" language="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<Promise<EnvsRaw>>('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);
|
|
}
|
|
```
|
|
|