-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
111 lines (95 loc) · 3.36 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
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
import { resolve } from 'path';
import git from 'git-rev-sync';
import { defineConfig, UserConfigExport } from 'vite';
// import { visualizer } from 'rollup-plugin-visualizer';
import pugPlugin from 'vite-plugin-pug';
import glsl from 'vite-plugin-glsl';
const root = resolve(__dirname, '.');
const source = resolve(__dirname, 'source');
const outDir = resolve(__dirname, 'dist');
const websiteDir = resolve(__dirname, 'website');
const pug_options = { localImports: true }
const pug_locals = {
name: "VARG Treemap Renderer",
base: '/'
}
let commit = '';
try {
commit = git.short(__dirname);
} catch {
// nothing
}
let branch = '';
try {
branch = git.branch(__dirname);
} catch {
// nothing
}
/**
* 3 modes are considered:
* - Development: don't emit anything, serve website and library in dev mode. (development, vite dev)
* - Lib Prod: Emit library build as cjs, umd, and es. (production, vite build)
* - Website Prod: Emit website with library as dependency. (website, vite build --mode=website)
*/
export default defineConfig(({ mode }) => {
const config: UserConfigExport = {
root,
define: {
__GIT_COMMIT__: JSON.stringify(commit),
__GIT_BRANCH__: JSON.stringify(branch),
__LIB_NAME__: JSON.stringify(process.env.npm_package_name),
__LIB_VERSION__: JSON.stringify(process.env.npm_package_version),
},
assetsInclude: ['**/*.fnt'],
};
switch (mode) {
case 'development':
config.build = {
outDir,
lib: {
entry: resolve(source, 'treemap-renderer.ts'),
name: 'treemap-renderer',
formats: ['cjs', 'umd', 'es'],
},
sourcemap: 'hidden',
};
break;
case 'website':
config.base = '/treemap-renderer/';
pug_locals.base = config.base;
config.build = {
outDir: websiteDir,
sourcemap: 'hidden',
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
explicit: resolve(__dirname, 'examples/csv-with-explicit-inner-nodes/index.html'),
grouping: resolve(__dirname, 'examples/csv-with-grouping/index.html'),
implicit: resolve(__dirname, 'examples/csv-with-implicit-inner-nodes/index.html'),
direct: resolve(__dirname, 'examples/direct-config/index.html'),
},
output: {
inlineDynamicImports: false,
}
}
};
break;
case 'production':
default:
config.build = {
outDir,
// emptyOutDir: true,
lib: {
entry: resolve(source, 'treemap-renderer.ts'),
name: 'treemap-renderer',
formats: ['cjs', 'umd', 'es'],
},
sourcemap: 'hidden',
};
config.define!.__DISABLE_ASSERTIONS__ = JSON.stringify(true);
config.define!.__LOG_VERBOSITY_THRESHOLD__ = JSON.stringify(2);
break;
}
config.plugins = [pugPlugin(pug_options, pug_locals), glsl()]; // visualizer()
return config;
});