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

inline svg

This commit is contained in:
Lukas Winkler 2023-02-01 21:42:40 +01:00
parent 6b5b8d211f
commit 926a741656
Signed by: lukas
GPG key ID: 54DE4D798D244853
2 changed files with 41 additions and 17 deletions

View file

@ -1,17 +0,0 @@
import {defineConfig} from "vite";
export default defineConfig({
plugins: [
// splitVendorChunkPlugin(),
// visualizer(),
],
build: {
sourcemap: true,
rollupOptions: {
input: {
"index": 'index.html',
"canvastest": 'canvastest.html',
},
}
}
})

41
vite.config.ts Normal file
View file

@ -0,0 +1,41 @@
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 {
name: 'vite-svg-patch-plugin',
transform: function (code, id) {
if (id.endsWith('.svg')) {
const extractedSvg = readFileSync(id, 'utf8');
return `export default '${svgToDataURL(extractedSvg)}'`;
}
return code;
}
} as Plugin;
}
export default defineConfig({
plugins: [
// splitVendorChunkPlugin(),
// visualizer(),
customSvgLoader()
],
build: {
sourcemap: true,
rollupOptions: {
input: {
"index": 'index.html',
"canvastest": 'canvastest.html',
},
}
}
})