@@ -5,6 +5,7 @@ import sass from 'sass';
55import stylus from 'stylus' ;
66import { extractICSS } from 'icss-utils' ;
77import tsModule from 'typescript/lib/tsserverlibrary' ;
8+ import { createMatchPath } from 'tsconfig-paths' ;
89import { Logger } from './logger' ;
910import { Options , CustomRenderer } from '../options' ;
1011
@@ -71,6 +72,14 @@ export const getClasses = ({
7172 } else if ( fileType === FileTypes . scss || fileType === FileTypes . sass ) {
7273 const filePath = getFilePath ( fileName ) ;
7374 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+ } ;
7483
7584 transformedCss = sass
7685 . renderSync ( {
@@ -80,6 +89,7 @@ export const getClasses = ({
8089 data : css . replace ( / ( @ i m p o r t [ ' " ] ) ~ (? ! \/ ) / gm, '$1' ) ,
8190 indentedSyntax : fileType === FileTypes . sass ,
8291 includePaths : [ filePath , 'node_modules' , ...( includePaths || [ ] ) ] ,
92+ importer : [ aliasImporter ] ,
8393 ...sassOptions ,
8494 } )
8595 . css . toString ( ) ;
0 commit comments