@@ -28,7 +28,7 @@ export default declare(({
2828 } ) => {
2929 const namedTemplate = `
3030 var SVG_NAME = function SVG_NAME(props) { return SVG_CODE; };
31- ${ SVG_DEFAULT_PROPS_CODE ? 'SVG_NAME.defaultProps = SVG_DEFAULT_PROPS_CODE;' : '' }
31+ ${ SVG_DEFAULT_PROPS_CODE ? 'SVG_NAME.defaultProps = SVG_DEFAULT_PROPS_CODE;' : '' }
3232 ${ IS_EXPORT ? 'export { SVG_NAME };' : '' }
3333 ` ;
3434 const anonymousTemplate = `
@@ -49,7 +49,7 @@ export default declare(({
4949 if ( typeof importPath !== 'string' ) {
5050 throw new TypeError ( '`applyPlugin` `importPath` must be a string' ) ;
5151 }
52- const { ignorePattern, caseSensitive, filename : providedFilename } = state . opts ;
52+ const { ignorePattern, caseSensitive, filename : providedFilename , root , alias } = state . opts ;
5353 const { file, filename } = state ;
5454 if ( ignorePattern ) {
5555 // Only set the ignoreRegex once:
@@ -62,10 +62,20 @@ export default declare(({
6262 // This plugin only applies for SVGs:
6363 if ( extname ( importPath ) === '.svg' ) {
6464 const iconPath = filename || providedFilename ;
65- const svgPath = resolve . sync ( importPath , { basedir : dirname ( iconPath ) } ) ;
66- if ( caseSensitive && ! fileExistsWithCaseSync ( svgPath ) ) {
67- throw new Error ( `File path didn't match case of file on disk: ${ svgPath } ` ) ;
65+ const aliasMatch = alias [ importPath . split ( '/' ) [ 0 ] ] ;
66+ let svgPath ;
67+
68+ if ( aliasMatch ) {
69+ const resolveRoot = resolve ( process . cwd ( ) , root || './' ) ;
70+ const aliasedPath = resolve ( resolveRoot , aliasMatch ) ;
71+ svgPath = aliasedPath + importPath . replace ( aliasMatch , '' ) ;
72+ } else {
73+ svgPath = resolve . sync ( importPath , { basedir : dirname ( iconPath ) } ) ;
74+ if ( caseSensitive && ! fileExistsWithCaseSync ( svgPath ) ) {
75+ throw new Error ( `File path didn't match case of file on disk: ${ svgPath } ` ) ;
76+ }
6877 }
78+
6979 if ( ! svgPath ) {
7080 throw new Error ( `File path does not exist: ${ importPath } ` ) ;
7181 }
0 commit comments