Skip to content

Commit

Permalink
fix: trim query from fileName passed to svgr (#82)
Browse files Browse the repository at this point in the history
closes #80
  • Loading branch information
Florens Verschelde authored Sep 20, 2023
1 parent 35f757b commit 2b8dd25
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ export default function viteSvgr({
exclude,
}: ViteSvgrOptions = {}): Plugin {
const filter = createFilter(include, exclude);
const postfixRE = /[?#].*$/s;

return {
name: "vite-plugin-svgr",
async transform(code, id) {
if (filter(id)) {
const { transform } = await import("@svgr/core");
const { default: jsx } = await import("@svgr/plugin-jsx");

const svgCode = await fs.promises.readFile(
id.replace(/\?.*$/, ""),
"utf8"
);
const filePath = id.replace(postfixRE, "");
const svgCode = await fs.promises.readFile(filePath, "utf8");

const componentCode = await transform(svgCode, svgrOptions, {
filePath: id,
filePath,
caller: {
previousExport: exportAsDefault ? null : code,
defaultPlugins: [jsx],
Expand Down

0 comments on commit 2b8dd25

Please sign in to comment.