Skip to content

Commit

Permalink
Fix build issue with empty source maps [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Feb 9, 2022
1 parent 09c5d81 commit 77ebfb4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 0.1.1

Fix build issue with empty source maps

## 0.1.0

Initial release
2 changes: 1 addition & 1 deletion 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",
Expand Down
12 changes: 9 additions & 3 deletions src/index.ts
Expand Up @@ -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}"`;
}
},
Expand Down

0 comments on commit 77ebfb4

Please sign in to comment.