Skip to content

Commit

Permalink
Use only load to skip source maps [publish]
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Feb 9, 2022
1 parent 77ebfb4 commit 3bbbeed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
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.1",
"version": "0.1.2",
"license": "MIT",
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
"main": "dist/index.js",
Expand Down
21 changes: 8 additions & 13 deletions src/index.ts
Expand Up @@ -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}"`;
}
},
Expand Down

0 comments on commit 3bbbeed

Please sign in to comment.