-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
vite.config.ts
63 lines (61 loc) · 1.38 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
import * as path from 'node:path'
import * as vite from 'vite'
const mangleMap: Record<string, string> = {
_compiled: '_c',
_programs: '_p',
_geometry: '_g',
_buffers: '_b',
_textures: '_t',
_samplers: '_s',
_FBOs: '_f',
_UBOs: '_u',
_pipelines: '_p',
}
export default vite.defineConfig({
root: process.argv[2] ? undefined : 'examples',
resolve: {
alias: {
four: path.resolve(__dirname, 'src'),
},
},
build: {
sourcemap: true,
target: 'esnext',
lib: {
formats: ['es'],
entry: 'src/index.ts',
fileName: '[name]',
},
rollupOptions: {
output: {
sourcemapExcludeSources: true,
},
},
},
plugins: [
{
name: 'vite-tsc',
generateBundle() {
this.emitFile({ type: 'asset', fileName: 'index.d.ts', source: `export * from '../src'` })
},
},
{
name: 'vite-minify',
transform(code, url) {
if (!url.includes('node_modules')) {
for (const key in mangleMap) code = code.replaceAll(key, mangleMap[key])
return vite.transformWithEsbuild(code, url, {
mangleProps: /^_\w{2,}/,
mangleQuoted: true,
})
}
},
renderChunk: {
order: 'post',
handler(code, { fileName }) {
return vite.transformWithEsbuild(code, fileName, { minify: true })
},
},
},
],
})