问题
I have set up webpack to load SVG files into my TSX port of the create-react-app, per this answer:
const logo = require('./logo.svg');
However, when I try to use it as follows I get a nasty 404.
<img src={logo} className="App-logo" alt="logo" />
Failed to load resource: the server responded with a status of 404 () [object%20Module]:1
This makes sense - I require
the svg, so it loads as a module, and you can't jolly well make a src
URL out of that.
That being said, how do I use an SVG loaded into a TSX file as a module via require
? Is this possible? I am aware the above answer is outvoted by the more popular approach specified here, but I want to see if this option can work as well. Because what is programming if not a thousand ways to skin a cat? Or shoot yourself in the foot...
来源:https://stackoverflow.com/questions/65205211/how-to-use-loaded-svg-module