mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 08:37:23 +00:00
42 lines
1011 B
TypeScript
42 lines
1011 B
TypeScript
import { build } from 'vite';
|
|
import { getPackageJson, getVantConfig } from '../common/constant.js';
|
|
import { mergeCustomViteConfig } from '../common/index.js';
|
|
import { getViteConfigForPackage } from '../config/vite.package.js';
|
|
import type { LibraryFormats } from 'vite';
|
|
|
|
export type BundleOption = {
|
|
minify?: boolean;
|
|
formats: LibraryFormats[];
|
|
external?: string[];
|
|
};
|
|
|
|
export async function compileBundles() {
|
|
const dependencies = getPackageJson().dependencies || {};
|
|
const external = Object.keys(dependencies);
|
|
|
|
const DEFAULT_OPTIONS: BundleOption[] = [
|
|
{
|
|
minify: false,
|
|
formats: ['umd'],
|
|
},
|
|
{
|
|
minify: true,
|
|
formats: ['umd'],
|
|
},
|
|
{
|
|
minify: false,
|
|
formats: ['es', 'cjs'],
|
|
external,
|
|
},
|
|
];
|
|
|
|
const bundleOptions: BundleOption[] =
|
|
getVantConfig().build?.bundleOptions || DEFAULT_OPTIONS;
|
|
|
|
await Promise.all(
|
|
bundleOptions.map((config) =>
|
|
build(mergeCustomViteConfig(getViteConfigForPackage(config)))
|
|
)
|
|
);
|
|
}
|