admin-vben5/internal/vite-config/src/config/index.ts
2024-06-08 19:49:06 +08:00

37 lines
940 B
TypeScript

import type { DefineConfig } from '../typing';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { defineApplicationConfig } from './application';
import { defineLibraryConfig } from './library';
export * from './application';
export * from './library';
function defineConfig(options: DefineConfig = {}) {
const { type = 'auto', ...defineOptions } = options;
let projectType = type;
// 根据包是否存在 index.html,自动判断类型
if (type === 'auto') {
const htmlPath = join(process.cwd(), 'index.html');
projectType = existsSync(htmlPath) ? 'application' : 'library';
}
switch (projectType) {
case 'application': {
return defineApplicationConfig(defineOptions);
}
case 'library': {
return defineLibraryConfig(defineOptions);
}
default: {
throw new Error(`Unsupported project type: ${projectType}`);
}
}
}
export { defineConfig };