-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrslib.config.ts
More file actions
173 lines (167 loc) · 3.35 KB
/
rslib.config.ts
File metadata and controls
173 lines (167 loc) · 3.35 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import { defineConfig } from '@rslib/core';
import pkg from './package.json';
import { glob } from 'glob';
import path from 'path';
const moduleName = 'cloud-utils';
const banner =
`/*!
* ${moduleName} v${pkg.version} (https://github.com/winjs-dev/cloud-utils)
* API https://winjs-dev.github.io/cloud-utils/
* Copyright 2017-${(new Date).getFullYear()} ${pkg.author.name}. All Rights Reserved
* Licensed under ${pkg.license} (https://github.com/winjs/cloud-utils/blob/master/LICENSE)
*/
`;
// 获取所有单独的函数文件
const getIndividualEntries = () => {
const files = glob.sync('src/*.ts', {
ignore: ['src/index.ts', 'src/__tests__/**']
});
const entries: Record<string, string> = {};
files.forEach(file => {
const fileName = path.basename(file, '.ts');
entries[fileName] = file;
});
return entries;
};
export default defineConfig({
lib: [
// 主入口点 - 统一构建
{
format: 'esm',
syntax: 'es5',
dts: true,
banner: {
js: banner
},
source: {
entry: {
index: 'src/index.ts'
}
},
output: {
distPath: {
root: './dist'
}
}
},
{
format: 'cjs',
syntax: 'es5',
dts: {
autoExtension: true
},
banner: {
js: banner
},
source: {
entry: {
index: 'src/index.ts'
}
},
output: {
distPath: {
root: './dist'
}
}
},
// 独立函数声明文件生成(在 dist 根目录)
{
format: 'esm',
syntax: 'es5',
dts: true,
banner: {
js: banner
},
source: {
entry: getIndividualEntries()
},
output: {
distPath: {
root: './dist'
},
filename: {
js: 'temp/[name].js' // 临时文件,稍后删除
}
}
},
// 独立函数构建 - ESM 格式(仅生成 JS 文件)
{
format: 'esm',
syntax: 'es5',
dts: false,
banner: {
js: banner
},
source: {
entry: getIndividualEntries()
},
output: {
distPath: {
root: './dist/esm'
},
filename: {
js: '[name].js'
}
}
},
// 独立函数构建 - CJS 格式(仅生成 JS 文件)
{
format: 'cjs',
syntax: 'es5',
dts: false,
banner: {
js: banner
},
source: {
entry: getIndividualEntries()
},
output: {
distPath: {
root: './dist/cjs'
},
filename: {
js: '[name].js'
}
}
},
// UMD 格式保持统一构建
{
format: 'umd',
umdName: 'cloud-utils',
banner: {
js: banner
},
source: {
entry: {
index: 'src/index.ts'
}
},
output: {
distPath: {
root: './dist/umd'
}
}
}
],
source: {
exclude: [
/src\/__tests__/
]
},
output: {
target: 'web'
},
// 性能优化配置,避免同时构建过多文件造成卡死
tools: {
rspack: {
experiments: {
// 关闭懒加载编译
lazyCompilation: false,
},
optimization: {
// 禁用代码分割,每个文件独立构建
splitChunks: false,
}
}
}
});