-
Notifications
You must be signed in to change notification settings - Fork 90
/
vite.config.js
45 lines (41 loc) · 1.06 KB
/
vite.config.js
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
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { defineConfig } from 'vite';
import { resolve } from 'path';
const config = {
es: {
entry: resolve(__dirname, 'src/main.ts'),
fileName: () => 'just-validate.es.js',
},
umd: {
entry: resolve(__dirname, 'src/main.umd.ts'),
fileName: () => 'just-validate.production.min.js',
},
};
const currentConfig = config[process.env.OUTPUT_FORMAT];
if (currentConfig === undefined) {
throw new Error('OUTPUT_FORMAT is not defined or is not valid');
}
export default defineConfig(({ command }) => {
if (command === 'serve') {
return {};
} else {
// command === 'build'
return {
build: {
outDir: 'dist',
emptyOutDir: false,
lib: {
...currentConfig,
formats: [process.env.OUTPUT_FORMAT],
name: 'JustValidate',
},
minify: 'terser',
rollupOptions: {
output: {
exports: process.env.OUTPUT_FORMAT === 'es' ? 'named' : 'default',
},
},
},
};
}
});