I have a Webpack-using codebase with lines like the following:
import Foo from './svg/icons/foo.svg';
and because of svg-react-loader it works.
However, using Webpack in our test environment would slow things down and add some headaches, so we run our tests (in Node) without it. This worked great up until we started importing SVGs like the one above, at which point we started to get errors like:
ReferenceError: React is not defined
at Object.<anonymous> (/Users/me/projects/foo/src/svg/icons/foo.svg:1:1)
(which I'm pretty sure happens because Node thinks the SVG file, made up of XML, is JSX, and thus tries to use React to read it).
So, I realize one solution would be to run our test environment through Webpack, but my question is, is there any way to make:
import Foo from './svg/icons/foo.svg';
not fail (or at least fail silently and keep going) when my non-Webpack test code runs it? For instance, is there anyway I could "shim" the Node loader so that if it sees a .svg it just moves along without doing anything?
Aucun commentaire:
Enregistrer un commentaire