From 20885513ae4fe4f03a64bb738d4816d8ed7c77c6 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Tue, 21 Jan 2020 10:06:30 -0500 Subject: [PATCH] fix(react): add fallback for SVG imports coming from non-TS/JS modules (#2351) --- packages/react/plugins/webpack.ts | 37 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/react/plugins/webpack.ts b/packages/react/plugins/webpack.ts index 9bcf9887a6..f96b1c7e51 100644 --- a/packages/react/plugins/webpack.ts +++ b/packages/react/plugins/webpack.ts @@ -18,17 +18,34 @@ function getWebpackConfig(config: Configuration) { }, { test: /\.svg$/, - issuer: { - test: /\.[jt]sx?$/ - }, - use: [ - '@svgr/webpack?-svgo,+titleProp,+ref![path]', + oneOf: [ + // If coming from JS/TS file, then transform into React component using SVGR. { - loader: 'url-loader', - options: { - limit: 10000, // 10kB - name: '[name].[hash:7].[ext]' - } + issuer: { + test: /\.[jt]sx?$/ + }, + use: [ + '@svgr/webpack?-svgo,+titleProp,+ref![path]', + { + loader: 'url-loader', + options: { + limit: 10000, // 10kB + name: '[name].[hash:7].[ext]' + } + } + ] + }, + // Fallback to plain URL loader. + { + use: [ + { + loader: 'url-loader', + options: { + limit: 10000, // 10kB + name: '[name].[hash:7].[ext]' + } + } + ] } ] }