From 77ebfb4cd46371232acc9d555ac482909c9ab806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Wed, 9 Feb 2022 11:25:35 +0100 Subject: [PATCH] Fix build issue with empty source maps [publish] --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/index.ts | 12 +++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e891a..1d891fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.1.1 + +Fix build issue with empty source maps + ## 0.1.0 Initial release diff --git a/package.json b/package.json index e271f49..6c40d60 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.0", + "version": "0.1.1", "license": "MIT", "author": "Arnaud Barré (https://github.com/ArnaudBarre)", "main": "dist/index.js", diff --git a/src/index.ts b/src/index.ts index 0debeab..bbcf359 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,12 +14,18 @@ export default function svgPlugin(): Plugin { return readFileSync(id.replace("?inline", ""), "utf-8"); } }, - transform(code, id) { + async transform(svg, id) { if (id.endsWith(".svg")) { - return transform(svgToJSX(code), { loader: "jsx" }); + const { code, warnings } = await transform(svgToJSX(svg), { + loader: "jsx", + }); + for (const warning of warnings) { + console.log(warning.location, warning.text); + } + return code; } if (id.endsWith(".svg?inline")) { - const base64 = Buffer.from(code).toString("base64"); + const base64 = Buffer.from(svg).toString("base64"); return `export default "data:image/svg+xml;base64,${base64}"`; } },