Skip to content

Commit 3bbbeed

Browse files
committed
Use only load to skip source maps [publish]
1 parent 77ebfb4 commit 3bbbeed

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.1.2
4+
5+
Use only `load` to skip source maps
6+
37
## 0.1.1
48

59
Fix build issue with empty source maps

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vite-plugin-fast-react-svg",
33
"description": "Turn SVG into React components, without Babel",
4-
"version": "0.1.1",
4+
"version": "0.1.2",
55
"license": "MIT",
66
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
77
"main": "dist/index.js",

src/index.ts

+8-13
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,21 @@ export default function svgPlugin(): Plugin {
66
return {
77
name: "svg",
88
enforce: "pre",
9-
load(id) {
9+
async load(id) {
1010
if (id.endsWith(".svg")) {
11-
return readFileSync(id, "utf-8");
12-
}
13-
if (id.endsWith(".svg?inline")) {
14-
return readFileSync(id.replace("?inline", ""), "utf-8");
15-
}
16-
},
17-
async transform(svg, id) {
18-
if (id.endsWith(".svg")) {
19-
const { code, warnings } = await transform(svgToJSX(svg), {
20-
loader: "jsx",
21-
});
11+
const { code, warnings } = await transform(
12+
svgToJSX(readFileSync(id, "utf-8")),
13+
{ loader: "jsx" }
14+
);
2215
for (const warning of warnings) {
2316
console.log(warning.location, warning.text);
2417
}
2518
return code;
2619
}
2720
if (id.endsWith(".svg?inline")) {
28-
const base64 = Buffer.from(svg).toString("base64");
21+
const base64 = Buffer.from(
22+
readFileSync(id.replace("?inline", ""), "utf-8")
23+
).toString("base64");
2924
return `export default "data:image/svg+xml;base64,${base64}"`;
3025
}
3126
},

0 commit comments

Comments
 (0)