Skip to content

Commit

Permalink
fix(v2): fix svg loader for CSS files (#3965)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
apurvaojas and slorber authored Dec 29, 2020
1 parent e5610a4 commit 5944226
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/docusaurus/src/webpack/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
32 changes: 22 additions & 10 deletions packages/docusaurus/src/webpack/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$/,
};
},

Expand Down

0 comments on commit 5944226

Please sign in to comment.