mirror of
https://github.com/Findus23/RainbowRoad.git
synced 2024-09-19 16:03:52 +02:00
inline svg
This commit is contained in:
parent
6b5b8d211f
commit
926a741656
2 changed files with 41 additions and 17 deletions
|
@ -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
41
vite.config.ts
Normal 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',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in a new issue