fix(v2): fix svg loader for CSS files (#3965)

* bug(v2): fix svg loader for styles re #3964

* ensure we only use SVGR loader in source code that can use React (ie not in CSS files)

* fix test

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Apurva Ojas 2020-12-29 19:17:57 +05:30 committed by GitHub
parent e5610a475d
commit 5944226eb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 12 deletions

View file

@ -135,8 +135,8 @@ describe('extending generated webpack config', () => {
describe('getFileLoaderUtils()', () => {
test('plugin svgo/removeViewBox should be disabled', () => {
const {use} = getFileLoaderUtils().rules.svg();
expect(use).toContainEqual(
const {oneOf} = getFileLoaderUtils().rules.svg();
expect(oneOf[0].use).toContainEqual(
expect.objectContaining({
loader: '@svgr/webpack',
options: expect.objectContaining({

View file

@ -300,21 +300,33 @@ export function getFileLoaderUtils(): Record<string, any> {
svg: (): RuleSetRule => {
return {
use: [
test: /\.svg?$/,
oneOf: [
{
loader: '@svgr/webpack',
options: {
prettier: false,
svgo: true,
svgoConfig: {
plugins: [{removeViewBox: false}],
use: [
{
loader: '@svgr/webpack',
options: {
prettier: false,
svgo: true,
svgoConfig: {
plugins: [{removeViewBox: false}],
},
titleProp: true,
ref: ![path],
},
},
titleProp: true,
ref: ![path],
],
// We don't want to use SVGR loader for non-React source code
// ie we don't want to use SVGR for CSS files...
issuer: {
test: /\.(ts|tsx|js|jsx|md|mdx)$/,
},
},
{
use: [loaders.url({folder: 'images'})],
},
],
test: /\.svg$/,
};
},