1
0
Fork 0
mirror of https://github.com/Findus23/RainbowRoad.git synced 2024-09-18 14:53:51 +02:00
RainbowRoad/vite.config.ts

44 lines
1 KiB
TypeScript
Raw Permalink Normal View History

2023-02-01 21:42:40 +01:00
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 {
2023-02-28 22:48:19 +01:00
enforce: "pre",
2023-02-01 21:42:40 +01:00
name: 'vite-svg-patch-plugin',
2023-02-28 22:48:19 +01:00
load: function (id: string): null | string {
if (!id.endsWith('.svg')) {
return null
2023-02-01 21:42:40 +01:00
}
2023-02-28 22:48:19 +01:00
const extractedSvg = readFileSync(id, 'utf8');
return `export default '${svgToDataURL(extractedSvg)}'`;
2023-02-01 21:42:40 +01:00
}
} as Plugin;
}
export default defineConfig({
plugins: [
// splitVendorChunkPlugin(),
// visualizer(),
customSvgLoader()
],
build: {
sourcemap: true,
rollupOptions: {
input: {
"index": 'index.html',
"canvastest": 'canvastest.html',
},
}
}
})