diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d891fd..9c17760 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.1.2 + +Use only `load` to skip source maps + ## 0.1.1 Fix build issue with empty source maps diff --git a/package.json b/package.json index 6c40d60..8790e3b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vite-plugin-fast-react-svg", "description": "Turn SVG into React components, without Babel", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "author": "Arnaud Barré (https://github.com/ArnaudBarre)", "main": "dist/index.js", diff --git a/src/index.ts b/src/index.ts index bbcf359..8d2eec5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,26 +6,21 @@ export default function svgPlugin(): Plugin { return { name: "svg", enforce: "pre", - load(id) { + async load(id) { if (id.endsWith(".svg")) { - return readFileSync(id, "utf-8"); - } - if (id.endsWith(".svg?inline")) { - return readFileSync(id.replace("?inline", ""), "utf-8"); - } - }, - async transform(svg, id) { - if (id.endsWith(".svg")) { - const { code, warnings } = await transform(svgToJSX(svg), { - loader: "jsx", - }); + const { code, warnings } = await transform( + svgToJSX(readFileSync(id, "utf-8")), + { loader: "jsx" } + ); for (const warning of warnings) { console.log(warning.location, warning.text); } return code; } if (id.endsWith(".svg?inline")) { - const base64 = Buffer.from(svg).toString("base64"); + const base64 = Buffer.from( + readFileSync(id.replace("?inline", ""), "utf-8") + ).toString("base64"); return `export default "data:image/svg+xml;base64,${base64}"`; } },