Cannot use svg-url-loader for svg files using the onCreateWebpackConfig api #32086
-
I am trying to use 'svg-url-loader' instead of 'url-loader' for svg files. I have installed it, and it works with webpack-inline-loaders. But to avoid repeating the process, I decided to use the onCreateWebpackConfig API to change the loader for svg files. I added the below code in gatsby-node.js. But the website is now not displaying any svg image but alt text. The src attribute of the img tag is using a faulty base64 encoded image and not the utf8 encoded svg xml tag.
The console is not logging any errors. I have created a local plugin at the /plugins dir, but it doesn't work also. I am developing my site on my local machine and building it using Gatsby Cloud. The problem persists in both places. Any help will be appreciated. Thank you. Here's the link to the minimal repro. Environment
flags in gatsby-config.js
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The problem here is that to use a custom loader in any framework, you have to disable the default loader first. Then you'll be able to add your custom loader. So, first, you have to disable the default, 'url-loader' and then set the 'svg-url-loader' for SVG files. I forgot to do that. `exports.onCreateWebpackConfig = ({
` Now it works fine. |
Beta Was this translation helpful? Give feedback.
The problem here is that to use a custom loader in any framework, you have to disable the default loader first. Then you'll be able to add your custom loader. So, first, you have to disable the default, 'url-loader' and then set the 'svg-url-loader' for SVG files. I forgot to do that.
`exports.onCreateWebpackConfig = ({
stage,
getConfig,
rules,
loaders,
plugins,
actions,
}) => {
const config = getConfig();