-
Notifications
You must be signed in to change notification settings - Fork 25
/
vite.config.ts
64 lines (55 loc) · 1.52 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path';
/** 0: no lib mode, 1: ES, 2: cjs */
const libMode = parseInt(process.env.LIB_MODE!) || 0;
/** 0: MapLibre, 1: MapBox */
const mapProvider = parseInt(process.env.MAP_MODE!) || 0;
const isES = libMode === 1;
const isMaplibre = mapProvider === 0;
const entry = `src/${isMaplibre ? 'maplibre' : 'mapbox'}.index.ts`;
let outDir = isMaplibre ? 'dist/maplibre' : 'dist';
outDir = `${outDir}/${isES ? 'es' : 'cjs'}`;
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
...(!libMode
// story mode
? {
base: '',
resolve: {
alias: {
'react-three-map/maplibre': resolve(__dirname, './src/maplibre.index.ts'),
'react-three-map': resolve(__dirname, './src/mapbox.index.ts'),
}
}
}
// lib mode
: {
publicDir: false,
build: {
minify: false,
lib: {
entry,
name: 'react-three-map',
formats: isES ? ['es'] : ['cjs'],
fileName: 'main',
},
outDir,
rollupOptions: {
output: !isES ? undefined : { sourcemap: true, preserveModules: true },
external: [
"@react-three/fiber",
"maplibre-gl",
"mapbox-gl",
"react",
'react/jsx-runtime',
"react-dom",
"react-map-gl",
"react-map-gl/maplibre",
"three",
]
},
},
})
})