Skip to content

Commit

Permalink
Refactor : SVGR 로더 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
jobkaeHenry committed Nov 8, 2023
1 parent ccaeeb9 commit 8972984
Show file tree
Hide file tree
Showing 11 changed files with 696 additions and 97 deletions.
17 changes: 17 additions & 0 deletions client/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ const config: StorybookConfig = {
"@": path.resolve(__dirname, "../src"),
"~": path.resolve(__dirname, "../src"),
};
const imageRule = config.module?.rules?.find(rule => {
const test = (rule as { test: RegExp }).test

if (!test) {
return false
}

return test.test('.svg')
}) as { [key: string]: any }

imageRule.exclude = /\.svg$/

config.module?.rules?.push({
test: /\.svg$/,
use: ['@svgr/webpack']
})

return config;
},
};
Expand Down
27 changes: 26 additions & 1 deletion client/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone'
output: 'standalone',
webpack(config, { isServer }) {
// @ts-ignore - rules is a private property that is not typed
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
},
// 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;
},
}

//For PWA
Expand Down
Loading

0 comments on commit 8972984

Please sign in to comment.