File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -26,20 +26,20 @@ export default function viteSvgr({
2626 exclude,
2727} : ViteSvgrOptions = { } ) : Plugin {
2828 const filter = createFilter ( include , exclude ) ;
29+ const postfixRE = / [ ? # ] .* $ / s;
30+
2931 return {
3032 name : "vite-plugin-svgr" ,
3133 async transform ( code , id ) {
3234 if ( filter ( id ) ) {
3335 const { transform } = await import ( "@svgr/core" ) ;
3436 const { default : jsx } = await import ( "@svgr/plugin-jsx" ) ;
3537
36- const svgCode = await fs . promises . readFile (
37- id . replace ( / \? .* $ / , "" ) ,
38- "utf8"
39- ) ;
38+ const filePath = id . replace ( postfixRE , "" ) ;
39+ const svgCode = await fs . promises . readFile ( filePath , "utf8" ) ;
4040
4141 const componentCode = await transform ( svgCode , svgrOptions , {
42- filePath : id ,
42+ filePath,
4343 caller : {
4444 previousExport : exportAsDefault ? null : code ,
4545 defaultPlugins : [ jsx ] ,
You can’t perform that action at this time.
0 commit comments