mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-11 17:50:29 +03:00
Vite plugin to add svg as inline data (#1072)
* add vite plugin to add svg as inline data * Add node types package
This commit is contained in:
parent
9a34daa2bc
commit
38bbc1c6f5
5 changed files with 42 additions and 7 deletions
16
viteSvgLoader.ts
Normal file
16
viteSvgLoader.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import svgToMiniDataURI from 'mini-svg-data-uri';
|
||||
import type { Plugin } from 'rollup';
|
||||
import fs from 'fs';
|
||||
|
||||
// TODO: remove this once https://github.com/vitejs/vite/pull/2909 gets merged
|
||||
export const svgLoader = (): Plugin => ({
|
||||
name: 'vite-svg-patch-plugin',
|
||||
transform: (code, id) => {
|
||||
if (id.endsWith('.svg')) {
|
||||
const extractedSvg = fs.readFileSync(id, 'utf8');
|
||||
const datauri = svgToMiniDataURI.toSrcset(extractedSvg);
|
||||
return `export default "${datauri}"`;
|
||||
}
|
||||
return code;
|
||||
},
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue