@@ -5,6 +5,7 @@ import sass from 'sass';
5
5
import stylus from 'stylus' ;
6
6
import { extractICSS } from 'icss-utils' ;
7
7
import tsModule from 'typescript/lib/tsserverlibrary' ;
8
+ import { createMatchPath } from 'tsconfig-paths' ;
8
9
import { Logger } from './logger' ;
9
10
import { Options , CustomRenderer } from '../options' ;
10
11
@@ -71,6 +72,14 @@ export const getClasses = ({
71
72
} else if ( fileType === FileTypes . scss || fileType === FileTypes . sass ) {
72
73
const filePath = getFilePath ( fileName ) ;
73
74
const { includePaths, ...sassOptions } = rendererOptions . sass || { } ;
75
+ const { baseUrl, paths } = compilerOptions ;
76
+ const matchPath =
77
+ baseUrl && paths ? createMatchPath ( path . resolve ( baseUrl ) , paths ) : null ;
78
+
79
+ const aliasImporter : sass . Importer = ( url ) => {
80
+ const newUrl = matchPath !== null ? matchPath ( url ) : undefined ;
81
+ return newUrl ? { file : newUrl } : null ;
82
+ } ;
74
83
75
84
transformedCss = sass
76
85
. renderSync ( {
@@ -80,6 +89,7 @@ export const getClasses = ({
80
89
data : css . replace ( / ( @ i m p o r t [ ' " ] ) ~ (? ! \/ ) / gm, '$1' ) ,
81
90
indentedSyntax : fileType === FileTypes . sass ,
82
91
includePaths : [ filePath , 'node_modules' , ...( includePaths || [ ] ) ] ,
92
+ importer : [ aliasImporter ] ,
83
93
...sassOptions ,
84
94
} )
85
95
. css . toString ( ) ;
0 commit comments