-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
52 lines (48 loc) · 1.23 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
import esbuild from 'esbuild'
import { readFile } from 'fs/promises'
import { resolve } from 'path'
import { defineConfig, loadEnv } from 'vite'
import { transform } from '@svgr/core'
import react from '@vitejs/plugin-react'
function svg() {
return {
name: 'svgr',
async transform(src: string, id: string) {
if (!id.endsWith('.svg')) {
return
}
const content = await readFile(id)
const component = (
await transform(content.toString(), {}, { componentName: 'SVG' })
).replace('export default SVG', 'export { SVG }')
const result = await esbuild.transform(`${component}\n${src}`, {
loader: 'jsx',
})
return {
code: result.code,
// map: result.map, // doesn't seem to work with vite build
}
},
}
}
export default ({ mode }) => {
return defineConfig({
plugins: [react(), svg()],
root: 'web',
build: {
sourcemap: true,
outDir: '../internal/web/static',
emptyOutDir: true,
},
resolve: {
alias: {
'@': resolve(__dirname, '/web'),
},
},
define: {
DROP_API_ROOT:
mode === 'development' ? "'http://localhost:8080/api/v1'" : "'/api/v1'",
'process.env': {},
},
})
}