My goal is to change svgo module's config the way that it does not remove id tags from svg file while importing it.
I have App.js:
import React from 'react'; import logo from './logo.svg'; import './App.css'; import { ReactComponent as Complex} from './simple.svg';
function App() { return ( ); }
export default App;
This is the svg related block inside my webpack.config.js:
...........................
{ test: /\.(js|mjs|jsx|ts|tsx)$/, include: paths.appSrc, loader: require.resolve('babel-loader'), options: { customize: require.resolve( 'babel-preset-react-app/webpack-overrides' ), presets: [ [ require.resolve('babel-preset-react-app'), { runtime: hasJsxRuntime ? 'automatic' : 'classic', }, ], ], // @remove-on-eject-begin babelrc: false, configFile: false, // Make sure we have a unique cache identifier, erring on the // side of caution. // We remove this when the user ejects because the default // is sane and uses Babel options. Instead of options, we use // the react-scripts and babel-preset-react-app versions. cacheIdentifier: getCacheIdentifier( isEnvProduction ? 'production' : isEnvDevelopment && 'development', [ 'babel-plugin-named-asset-import', 'babel-preset-react-app', 'react-dev-utils', 'react-scripts', ] ), // @remove-on-eject-end plugins: [ isEnvDevelopment && shouldUseReactRefresh && require.resolve('react-refresh/babel'), ].filter(Boolean), // This is a feature ofbabel-loaderfor webpack (not Babel itself). // It enables caching results in ./node_modules/.cache/babel-loader/ // directory for faster rebuilds. cacheDirectory: true, // See #6846 for context on why cacheCompression is disabled cacheCompression: false, compact: isEnvProduction, }, }, ...............................
node_modules, that's not where your work goes. Also, note that svgo is doing the right thing here: if you're importing SVG files, their id attributes don't matter if you're using them as img source, and their internalidvalues are incompatible with the document you're putting them in if you're inlining them directly as HTML5. Instead ask yourself why you need thoseidattributes, because React can already get to whatever you render out in the normal, React way.