Skip to content

Commit

Permalink
fix(nextjs): Svg should work when svgr is true in next config
Browse files Browse the repository at this point in the history
closes: #20972
  • Loading branch information
ndcunningham committed Feb 10, 2024
1 parent 5911ca6 commit 759b6f1
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 deletions packages/next/plugins/with-nx.ts
Expand Up @@ -333,40 +333,22 @@ export function getNextConfig(

// Default SVGR support to be on for projects.
if (nx?.svgr !== false) {
config.module.rules.push({
test: /\.svg$/,
oneOf: [
// If coming from JS/TS file, then transform into React component using SVGR.
{
issuer: /\.[jt]sx?$/,
use: [
{
loader: require.resolve('@svgr/webpack'),
options: {
svgo: false,
titleProp: true,
ref: true,
},
},
{
loader: require.resolve('url-loader'),
options: {
limit: 10000, // 10kB
name: '[name].[hash:7].[ext]',
},
},
],
},
// Fallback to plain URL loader if someone just imports the SVG and references it on the <img src> tag
{
loader: require.resolve('url-loader'),
options: {
limit: 10000, // 10kB
name: '[name].[hash:7].[ext]',
},
},
],
});
config.module.rules.push(
// Apply rule for svg imports ending in ?url
{
test: /\.svg$/i,
type: 'asset',
resourceQuery: /url/, // apply to *.svg?url
},

// Convert all other svg imports to React components
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
resourceQuery: { not: [/url/] },
use: ['@svgr/webpack'],
}
);
}

return userWebpack(config, options);
Expand Down

0 comments on commit 759b6f1

Please sign in to comment.