2024-06-08 11:49:06 +00:00
|
|
|
import type { DefineConfig } from '../typing';
|
|
|
|
|
2024-06-02 15:50:58 +00:00
|
|
|
import { existsSync } from 'node:fs';
|
2024-05-19 13:20:42 +00:00
|
|
|
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');
|
2024-06-02 15:50:58 +00:00
|
|
|
projectType = existsSync(htmlPath) ? 'application' : 'library';
|
2024-05-19 13:20:42 +00:00
|
|
|
}
|
|
|
|
|
2024-06-02 15:50:58 +00:00
|
|
|
switch (projectType) {
|
|
|
|
case 'application': {
|
|
|
|
return defineApplicationConfig(defineOptions);
|
|
|
|
}
|
|
|
|
case 'library': {
|
|
|
|
return defineLibraryConfig(defineOptions);
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
throw new Error(`Unsupported project type: ${projectType}`);
|
|
|
|
}
|
2024-05-19 13:20:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export { defineConfig };
|