INNER CODE UNIT · JavaScript
webpack
gadingnst/fullstack-next-template · webpack.config.js:2
function webpack(config) {
/**
* handle SVGR module
* Configures webpack to handle SVG files with SVGR. SVGR optimizes and transforms SVG files into React components.
* @see https://react-svgr.com/docs/next/
* @see https://react-svgr.com/docs/webpack/
*/
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.('.svg'));
config.module.rules.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/ // *.svg?url
},