vant/packages/vant-cli/src/config/vite.package.ts
2021-10-28 20:09:00 +08:00

40 lines
980 B
TypeScript

import { join } from 'path';
import type { InlineConfig } from 'vite';
import { setBuildTarget } from '../common/index.js';
import { CWD, ES_DIR, getVantConfig, LIB_DIR } from '../common/constant.js';
export function getViteConfigForPackage(minify: boolean): InlineConfig {
setBuildTarget('package');
const { name } = getVantConfig();
return {
root: CWD,
logLevel: 'silent',
build: {
lib: {
name,
entry: join(ES_DIR, 'index.js'),
fileName: (format: string) => {
const suffix = format === 'umd' ? '' : `.${format}`;
return minify ? `${name}${suffix}.min.js` : `${name}${suffix}.js`;
},
},
// terser has better compression than esbuild
minify: minify ? 'terser' : false,
rollupOptions: {
external: ['vue'],
output: {
dir: LIB_DIR,
exports: 'named',
globals: {
vue: 'Vue',
},
},
},
},
};
}