I am using create-react-app
to build my React application. I’ve added react-svg-loader
and using it in this way:
JavaScript
x
3
1
export { default as arrowLeft } from '-!react-svg-loader!./arrow-left.svg';
2
export { default as arrowRight } from '-!react-svg-loader!./arrow-right.svg';
3
But when I am trying to run yarn build
– process fails on minification step:
Creating an optimized production build… Failed to compile.
Failed to minify the code from this file:
JavaScript121./node_modules/react-svg-loader/lib/loader.js!./src/icons/arrow-left.svg:6
2
Read more here: http://bit .ly/2tRViJ9
Can I fix it somehow without ejecting?
Advertisement
Answer
The best solution I found is react-app-rewired + react-app-rewire-svg-react-loader. Inside config-overrides.js
, which is used by this library you will have an access to webpack config. So it can be easy changed.
My config looks like this:
JavaScript
1
6
1
const rewireSvgReactLoader = require('react-app-rewire-svg-react-loader');
2
3
module.exports = function override(config, env) {
4
return rewireSvgReactLoader(config, env);
5
};
6