-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.ts
More file actions
90 lines (88 loc) · 2.74 KB
/
vite.config.ts
File metadata and controls
90 lines (88 loc) · 2.74 KB
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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import dts from 'vite-plugin-dts';
// Use DEBUG=1 to generate sourcemaps and disable minification for debugging
const isDebug = process.env.DEBUG === '1';
export default defineConfig({
plugins: [
react(),
dts({
include: ['src'],
outDir: 'dist/types',
rollupTypes: false,
}),
],
optimizeDeps: {
esbuildOptions: {
// Avoid downleveling class fields in maplibre-gl worker bundle (prevents __publicField errors).
target: 'es2022',
},
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
build: {
lib: {
entry: {
index: resolve(__dirname, 'src/index.ts'),
react: resolve(__dirname, 'src/react.ts'),
},
name: 'MapLibreGLComponents',
formats: ['es', 'cjs'],
fileName: (format, entryName) => {
const ext = format === 'es' ? 'mjs' : 'cjs';
return `${entryName}.${ext}`;
},
},
rollupOptions: {
// External packages that should not be bundled
// shpjs and @duckdb/duckdb-wasm are optional dependencies loaded at runtime
// @deck.gl/*, @luma.gl/*, @loaders.gl/*, @math.gl/*, @probe.gl/*, three,
// @dvt3d/*, @developmentseed/deck.gl-*, and @carbonplan/* are peer dependencies
// to avoid double initialization of luma.gl when consumers also use these packages
external: [
'react',
'react-dom',
'maplibre-gl',
'shpjs',
'@duckdb/duckdb-wasm',
'jspdf',
/^@deck\.gl\//,
/^@luma\.gl\//,
/^@loaders\.gl\//,
/^@math\.gl\//,
/^@probe\.gl\//,
'three',
/^@dvt3d\//,
/^@developmentseed\//,
/^@carbonplan\//,
],
onwarn(warning, defaultHandler) {
// Suppress "spawn" not exported warning from @loaders.gl/worker-utils
// (it imports Node.js child_process which doesn't exist in browser builds)
if (warning.code === 'MISSING_EXPORT' && warning.message.includes('"spawn"')) return;
defaultHandler(warning);
},
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'maplibre-gl': 'maplibregl',
},
assetFileNames: (assetInfo) => {
if (assetInfo.name === 'style.css') return 'maplibre-gl-components.css';
return assetInfo.name || '';
},
},
},
cssCodeSplit: false,
// Production: no sourcemaps, minified for smaller package size
// Debug: sourcemaps enabled, no minification for easier debugging
// Use `DEBUG=1 npm run build` to generate debuggable artifacts
sourcemap: isDebug,
minify: isDebug ? false : 'esbuild',
},
});