File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -443,10 +443,22 @@ export function createConfig(config = {}, options = {}) {
443
443
verbose : false ,
444
444
version : pkg . version ,
445
445
getComponentPathLine ( componentPath ) {
446
- let name = basename ( componentPath , '.js' ) ;
446
+ let name = '' ;
447
+ let ext = '' ;
448
+ let key = null ;
449
+ if ( / .j s $ / . test ( componentPath ) ) {
450
+ name = basename ( componentPath , '.js' ) ;
451
+ } else if ( / .s v g $ / . test ( componentPath ) ) {
452
+ // we can import svg as react component using @svgr /webpack
453
+ name = basename ( componentPath , '.svg' ) ;
454
+ name = `${ name [ 0 ] . toUpperCase ( ) } ${ name . slice ( 1 ) } ` ;
455
+ key = 'ReactComponent' ;
456
+ ext = '.svg' ;
457
+ }
447
458
const dir = name === 'index' ? dirname ( componentPath ) : `${ dirname ( componentPath ) } /${ name } ` ;
448
459
name = name === 'index' ? basename ( dir ) : name ;
449
- return `import ${ name } from '${ pkg . name } /${ dir . replace ( / ^ s r c \/ / , 'lib/' ) } ';` ;
460
+ const es6import = key ? `{ ${ key } as ${ name } }` : name ;
461
+ return `import ${ es6import } from '${ pkg . name } /${ dir . replace ( / ^ s r c \/ / , 'lib/' ) } ${ ext } ';` ;
450
462
} ,
451
463
// this is useful for markdown generated with documentationjs
452
464
updateExample ( props ) {
You can’t perform that action at this time.
0 commit comments