-
Notifications
You must be signed in to change notification settings - Fork 1
/
docs-viterun.config.ts
231 lines (220 loc) · 6.02 KB
/
docs-viterun.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import {resolve} from "node:path";
import {defineViteRunConfig, viteRunLogPlugin, ViteRunHandleFunctionOptions} from "vite-run";
/*
* This file is just a template, and running it directly will result in an error.
* You can delete or add the configuration you need,
* and configure it according to the actual project situation.
* If you are already using this tool and do not need any comments,
* you can run vite run -- init - p to regenerate the vite run. config configuration without comments
* */
export default defineViteRunConfig({
/*
* baseConfig A function that accepts an object or returns a vite configuration object,
* This function generally only contains information that is common to all configurations,
* and is not a complete vite configuration
*
* All app configurations are merged with baseConfig as the final vite configuration.
* For example, the following lib.build contains two configurations ['es'] and ['build_lib','umd']
* the merge rule is:
* viteConfig1 = es + baseConfig
* viteConfig2 = build_lib + umd + baseConfig
*/
baseConfig: getBaseConfig,
// Specify the app name to manage, The app name is the folder name,A package is also called an app
packages: [
// Manage all apps in a folder
'packages/*',
// Explicitly specify app to manage
'examples/you-apps-folder',
// './' will manage the main app, which is named the current project name
'./'
],
// Configure the vite configuration block information to be executed for the currently managed app
targets: {
/* syntax:
appName(or say packageName) :{
configurationName: [
configuration block1,
[configuration block1,configuration block2,....],
[configuration block1,configuration block3,....],
]
}
Final vite configuration = merge(configuration group) + baseConfig
*/
/* Here 'you-app-name' is the managed by vite-run app name, which must be the directory specified in packages */
'you-app-name': {
build: [
/* The es configuration here will be combined with baseConfig for the final vite configuration
* The es configuration here points to the object that is the build.es configuration below
*/
// You can also write it as a single string, but then only es can merge with baseConfig
// 'es',
['es'],
/*
* The build_lib and umd configurations here will be combined with baseConfig for the final vite configuration
* build_lib and umd are merged from left to right, with later values overwriting previous values if there is a deep merge conflict
* For example configuration block:
* block1 = {
a1:1,
b1:2,
c1:{
d1:3,
e1:4
}
}
block2 = {
b1:100,
c1:{
d1:200
}
}
block1 + block2 === {
a1:1,
b1:100,
c1:{
d1:200,
e1:4
}
}
The implementation here is the generic deepmerge approach
*/
['plugin1', 'umd']
],
types: [
['types']
],
dev: [
['watch']
]
},
'you-app-name2': {
build: [
['es'],
['umd', 'minify']
],
dev: [
['10000']
]
},
},
/*
* syntax:
* viteOriginalField:{
* configurationBlockName:configurationBlock
* }
* configurationBlock is the original configuration of vite
*
* The Vite-run tool simply names the original configuration by wrapping it around
* it so that it can be freely combined with the block names
* to increase the flexibility of building the final configuration of vite
*
* notice:
* Not only does build support this configuration block mode,
* but all vite built-in configuration keywords can be used to generate
* and name configuration blocks in this way
* */
build: {
umd: {
lib: {
formats: ['umd']
}
},
es: {
lib: {
formats: ['es']
},
},
watch: {
watch: {},
},
minify: {
minify: true
},
/*
* The configuration block supports receiving a function
* so that you can more flexibly generate the content of the configuration block
*
* notice:
* If you want to get better ts type hints, you should use the arrow function
*/
build_lib: (options) => {
return {
lib: {
entry: resolve(options.packagePath, 'main.ts'),
formats: ['umd'],
name: options.name,
fileName: (format: string) => `index.${format}.js`,
},
watch: {},
rollupOptions: {
watch: {},
external: [],
output: {}
},
}
},
},
server: {
10000: {
// open: true,
port: 10000
},
},
preview: {
'20000': {
port: 20000,
}
},
plugins: {
plugin1: (_) => {
return [
{
name: 'example-plugin1',
apply: 'build',
resolveId(_) {
},
},
]
},
plugin2: [
{
name: 'example-plugin2',
resolveId(_) {
},
},
]
}
})
function getBaseConfig(options: ViteRunHandleFunctionOptions) {
return {
resolve: {
extensions: [".ts", ".js", '.css'],
alias: {
"@": resolve(options.packagePath, 'src'),
types: resolve(options.packagePath, 'src/types')
}
},
build: {
emptyOutDir: false,
minify: false,
rollupOptions: {
output: {
sourcemap: false,
globals: {}
},
treeshake: true
},
},
plugins: [
viteRunLogPlugin({
// Intercept and output console logs
// server: {
// viteLog: true,
// viteRunLog: {
// sizeAntOutputPrint:false
// }
// }
}),
]
}
}