-
Notifications
You must be signed in to change notification settings - Fork 165
/
vite.config.ts
56 lines (52 loc) · 1.6 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
import { defineConfig, UserConfig } from 'vite';
import dts from 'vite-plugin-dts';
import cp from 'vite-plugin-cp';
import nodeExternals from 'rollup-plugin-node-externals';
import { visualizer } from 'rollup-plugin-visualizer';
// vite config for building nebula lib modules https://vitejs.dev/config/
export default defineConfig((env) => {
const viteBuildConfig: UserConfig = {
build: {
// clean dist dir before build
emptyOutDir: true,
outDir: 'dist',
sourcemap: true,
lib: {
entry: 'src/index.ts',
formats: ['es', 'cjs'],
fileName: 'index',
},
},
plugins: [
// do not bundle npm dependencies, peerDependencies and optionalDependencies
{
...nodeExternals({
peerDeps: true,
include: /^@nebula\.gl/,
}),
enforce: 'pre',
},
// generate types
dts({ rollupTypes: true }),
],
};
// copy /README.md into module dir if necessary
const hasOwnReadme =
process.cwd().endsWith('react-map-gl-draw') || process.cwd().endsWith('overlays');
if (!hasOwnReadme) {
viteBuildConfig.plugins.push(cp({ targets: [{ src: '../../README.md', dest: './' }] }));
}
// Visualize and analyze your Rollup bundle to see which modules are taking up space
// set ROLLUP_VISUALIZER=1 env var to enable generating rollup_stats.html
if (process.env['ROLLUP_VISUALIZER']) {
viteBuildConfig.plugins.push(
visualizer({
filename: 'rollup_stats.html',
// template: 'list',
gzipSize: true,
sourcemap: true,
})
);
}
return viteBuildConfig;
});