-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.config.ts
75 lines (70 loc) · 1.74 KB
/
build.config.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import pgk from './package.json';
const GLOBAL_LIB_NAME = 'ChameleonMaterialDemo';
const envDefine = {
__PACKAGE_VERSION__: JSON.stringify(pgk.version),
__PACKAGE_NAME__: JSON.stringify(pgk.name),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
__GLOBAL_LIB_NAME__: JSON.stringify(GLOBAL_LIB_NAME),
};
// 开发模式默认读取 index.html 作为开发模式入口
// entry 作为打包库入口
const LIB_NAME = process.env.LIB_NAME;
let buildConfig: any = {
entry: './src/index.tsx',
vite: {
define: envDefine,
plugins: [],
},
};
if (LIB_NAME) {
const libConfig = {
entry: './src/index.tsx',
libName: GLOBAL_LIB_NAME,
formats: process.env.DEV ? ['umd'] : ['es', 'cjs', 'umd'],
fileName: 'index',
external: ['react'],
global: {
react: 'React',
},
// 额外的 vite 配置
vite: {
define: {},
},
};
const metaConfig = {
entry: './src/meta.tsx',
libName: `${GLOBAL_LIB_NAME}Meta`,
formats: ['es', 'cjs'],
fileName: 'meta',
external: ['react'],
global: {
react: 'React',
},
// 额外的 vite 配置
vite: {
build: {
emptyOutDir: false,
assetFileNames: (assetInfo) => {
if (assetInfo.name === 'style.css' && LIB_NAME !== 'index')
return `${LIB_NAME}.css`;
return assetInfo.name;
},
lib: {
fileName: (format) => {
if (format === 'es') {
return 'meta.js';
} else {
return `meta.${format}.js`;
}
},
},
},
define: envDefine,
},
};
buildConfig = libConfig;
if (process.env.LIB_NAME === 'meta') {
buildConfig = metaConfig;
}
}
export default buildConfig;