Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom icon and SVG handling #20

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,34 @@ const config: StorybookConfig = {

typescript: {
reactDocgen: 'react-docgen-typescript'
},
webpackFinal: async config => {
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module?.rules?.find((rule) =>
(rule as { test?: RegExp })?.test?.test(".svg")
) as { [key: string]: any }

config.module?.rules?.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/ // *.svg?url
},
// Convert all other *.svg imports to React components
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: {
not: [...(fileLoaderRule?.resourceQuery?.not || []), /url/]
}, // exclude if *.svg?url
use: ["@svgr/webpack"]
}
)
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i

return config
}
};
export default config;
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,6 @@ module.exports = {
// watchman: true,
moduleNameMapper: {
".(css|less|scss)$": "identity-obj-proxy",
"\\.svg": "<rootDir>/src/components/__mocks__/SvgMock.js",
},
};
Loading
Loading