Blame view

泰额版/Food Labeling Management Code/Yi.Vben5.Vue3/internal/vite-config/src/config/index.ts 963 Bytes
383e20a3   杨鑫   拉取
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  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(
    userConfigPromise?: DefineConfig,
    type: 'application' | 'auto' | 'library' = 'auto',
  ) {
    let projectType = type;
  
    // 根据包是否存在 index.html,自动判断类型
    if (projectType === 'auto') {
      const htmlPath = join(process.cwd(), 'index.html');
      projectType = existsSync(htmlPath) ? 'application' : 'library';
    }
  
    switch (projectType) {
      case 'application': {
        return defineApplicationConfig(userConfigPromise);
      }
      case 'library': {
        return defineLibraryConfig(userConfigPromise);
      }
      default: {
        throw new Error(`Unsupported project type: ${projectType}`);
      }
    }
  }
  
  export { defineConfig };