index.ts 940 B

123456789101112131415161718192021222324252627282930313233343536
  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(options: DefineConfig = {}) {
  9. const { type = 'auto', ...defineOptions } = options;
  10. let projectType = type;
  11. // 根据包是否存在 index.html,自动判断类型
  12. if (type === 'auto') {
  13. const htmlPath = join(process.cwd(), 'index.html');
  14. projectType = existsSync(htmlPath) ? 'application' : 'library';
  15. }
  16. switch (projectType) {
  17. case 'application': {
  18. return defineApplicationConfig(defineOptions);
  19. }
  20. case 'library': {
  21. return defineLibraryConfig(defineOptions);
  22. }
  23. default: {
  24. throw new Error(`Unsupported project type: ${projectType}`);
  25. }
  26. }
  27. }
  28. export { defineConfig };