File tree Expand file tree Collapse file tree 1 file changed +32
-16
lines changed
packages/react-scripts/config Expand file tree Collapse file tree 1 file changed +32
-16
lines changed Original file line number Diff line number Diff line change @@ -436,29 +436,45 @@ module.exports = function (webpackEnv) {
436
436
} ,
437
437
{
438
438
test : / \. s v g $ / ,
439
- use : [
439
+ oneOf : [
440
+ // Transform SVG into a React component when imported from JavaScript/TypeScript/Markdown files.
440
441
{
441
- loader : require . resolve ( '@svgr/webpack' ) ,
442
- options : {
443
- prettier : false ,
444
- svgo : false ,
445
- svgoConfig : {
446
- plugins : [ { removeViewBox : false } ] ,
442
+ issuer : { and : [ / \. ( t s | t s x | j s | j s x | m d | m d x ) $ / ] } ,
443
+ use : [
444
+ {
445
+ loader : require . resolve ( '@svgr/webpack' ) ,
446
+ options : {
447
+ prettier : false ,
448
+ svgo : false ,
449
+ svgoConfig : {
450
+ plugins : [ { removeViewBox : false } ] ,
451
+ } ,
452
+ titleProp : true ,
453
+ ref : true ,
454
+ } ,
447
455
} ,
448
- titleProp : true ,
449
- ref : true ,
450
- } ,
456
+ {
457
+ loader : require . resolve ( 'file-loader' ) ,
458
+ options : {
459
+ name : 'static/media/[name].[hash].[ext]' ,
460
+ } ,
461
+ } ,
462
+ ] ,
451
463
} ,
464
+ // Fallback: Inline SVG as a url-encoded data URL for all other imports.
452
465
{
453
- loader : require . resolve ( 'file-loader' ) ,
454
- options : {
455
- name : 'static/media/[name].[hash].[ext]' ,
466
+ type : 'asset/inline' ,
467
+ generator : {
468
+ dataUrl : content => {
469
+ // Convert the raw SVG content to a UTF-8 encoded data URL.
470
+ const svgString = content . toString ( ) ;
471
+ return `data:image/svg+xml;charset=utf-8,${ encodeURIComponent (
472
+ svgString
473
+ ) } `;
474
+ } ,
456
475
} ,
457
476
} ,
458
477
] ,
459
- issuer : {
460
- and : [ / \. ( t s | t s x | j s | j s x | m d | m d x ) $ / ] ,
461
- } ,
462
478
} ,
463
479
{
464
480
test : / \. ( j s | m j s | j s x | t s | t s x ) $ / ,
You can’t perform that action at this time.
0 commit comments