index.ts 956 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import type { DefineConfig } from '../typing';
  2. import { existsSync } from 'node:fs';
  3. import { join } from 'node:path';
  4. import { defineApplicationConfig } from './application';
  5. import { defineLibraryConfig } from './library';
  6. export * from './application';
  7. export * from './library';
  8. function defineConfig(
  9. userConfigPromise?: DefineConfig,
  10. type: 'application' | 'auto' | 'library' = 'auto',
  11. ) {
  12. let projectType = type;
  13. // 根据包是否存在 index.html,自动判断类型
  14. if (type === 'auto') {
  15. const htmlPath = join(process.cwd(), 'index.html');
  16. projectType = existsSync(htmlPath) ? 'application' : 'library';
  17. }
  18. switch (projectType) {
  19. case 'application': {
  20. return defineApplicationConfig(userConfigPromise);
  21. }
  22. case 'library': {
  23. return defineLibraryConfig(userConfigPromise);
  24. }
  25. default: {
  26. throw new Error(`Unsupported project type: ${projectType}`);
  27. }
  28. }
  29. }
  30. export { defineConfig };