-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
vite.config.ts
57 lines (51 loc) · 1.71 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
import { readFileSync } from 'node:fs';
import dts from 'vite-plugin-dts';
import { defineConfig } from 'vite';
import bannerPlugin from 'vite-plugin-banner';
import { CSS_CLASSES } from './src/constants';
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'));
const banner = `
/*!
* ${pkg.name} - v${pkg.version}
* ${pkg.homepage}
* Built: ${new Date()}
*/
`;
const additionalData = Object.keys(CSS_CLASSES).reduce(
(accumulator, current) => `${accumulator}$${current}:${CSS_CLASSES[String(current)]};`,
'',
);
const css = { preprocessorOptions: { scss: { additionalData } } };
export default defineConfig(({ command }) =>
command === 'serve'
? {
css,
build: { target: 'es2020' },
}
: {
css,
build: {
target: 'es2020',
lib: {
entry: './src/main.ts',
name: 'ContextMenu',
fileName: 'ol-contextmenu',
formats: ['es', 'umd', 'iife'],
},
rollupOptions: {
external: [/^ol.*/],
output: {
globals: {
'ol/MapBrowserEvent': 'ol.MapBrowserEvent',
'ol/control/Control': 'ol.control.Control',
},
assetFileNames: () => 'ol-contextmenu.css',
},
},
},
plugins: [dts({ insertTypesEntry: true }), bannerPlugin(banner)],
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
},
},
);