-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
62 lines (52 loc) · 1.73 KB
/
vite.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
import { existsSync } from 'fs';
import { resolve } from 'path';
import git from 'git-rev-sync';
import { defineConfig, UserConfigExport } from 'vite';
// import { visualizer } from 'rollup-plugin-visualizer';
const root = resolve(__dirname, 'source');
const outDir = resolve(__dirname, 'dist');
const gitExists = existsSync(resolve(__dirname, '.git'))
export default defineConfig(({ mode }) => {
const config: UserConfigExport = {
root,
build: {
outDir,
lib: {
entry: resolve(root, 'index.ts'),
name: 'haeley.colors',
formats: ['cjs', 'umd', 'es'],
},
sourcemap: 'hidden',
rollupOptions: {
external: [
'@haeley/auxiliaries',
'@haeley/math'
],
output: {
globals: {
'@haeley/auxiliaries': 'haeley.auxiliaries',
'@haeley/math': 'haeley.math'
}
}
}
},
define: {
__GIT_COMMIT__: JSON.stringify(gitExists ? git.short(__dirname) : undefined),
__GIT_BRANCH__: JSON.stringify(gitExists ? git.branch(__dirname) : undefined),
__LIB_NAME__: JSON.stringify(process.env.npm_package_name),
__LIB_VERSION__: JSON.stringify(process.env.npm_package_version),
},
// plugins: [visualizer()]
};
switch (mode) {
case 'development':
config.build.outDir = outDir;
break;
case 'production':
default:
config.build.emptyOutDir = true;
break;
}
// console.log(config);
return config;
});