-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.ts
More file actions
57 lines (53 loc) · 1.42 KB
/
vite.config.ts
File metadata and controls
57 lines (53 loc) · 1.42 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
import { defineConfig, type Plugin } from 'vite'
import fs from 'fs'
import path from 'path'
import preact from '@preact/preset-vite'
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
console.log("Build mode", mode);
const devBuild = mode === 'development';
return {
plugins: [preact(), selectiveOutDirCleanup({ preserve: ['data'] })],
build: {
sourcemap: devBuild,
emptyOutDir: false,
chunkSizeWarningLimit: 1100, // For maplibre-gl
rollupOptions: {
output: {
manualChunks: {
preact: ['preact', 'preact/hooks', 'preact/compat'],
maplibre: ['maplibre-gl']
}
}
}
},
server: {
proxy: {
'/data': {
target: 'http://localhost:8801',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/data/, ''),
}
},
}
}
});
function selectiveOutDirCleanup(options?: { preserve?: string[] }) {
const { preserve = [] } = options || {};
let outDir = 'dist';
return {
name: 'selective-out-dir-cleanup',
configResolved(config) {
outDir = config.build.outDir;
},
buildStart() {
if (fs.existsSync(outDir)) {
fs.readdirSync(outDir).forEach(file => {
if (!preserve.includes(file)) {
fs.rmSync(path.join(outDir, file), { recursive: true, force: true });
}
});
}
}
} as Plugin
}