-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
43 lines (38 loc) · 1.03 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
import {defineConfig, Plugin} from "vite";
import {readFileSync} from "fs";
function svgToDataURL(svgStr: string): string {
const encoded = encodeURIComponent(svgStr)
.replace(/'/g, '%27')
.replace(/"/g, '%22')
const header = 'data:image/svg+xml,'
return header + encoded
}
function customSvgLoader() {
return {
enforce: "pre",
name: 'vite-svg-patch-plugin',
load: function (id: string): null | string {
if (!id.endsWith('.svg')) {
return null
}
const extractedSvg = readFileSync(id, 'utf8');
return `export default '${svgToDataURL(extractedSvg)}'`;
}
} as Plugin;
}
export default defineConfig({
plugins: [
// splitVendorChunkPlugin(),
// visualizer(),
customSvgLoader()
],
build: {
sourcemap: true,
rollupOptions: {
input: {
"index": 'index.html',
"canvastest": 'canvastest.html',
},
}
}
})