1
- import { Result } from 'sass' ;
1
+ import type { Importer , Result } from 'sass' ;
2
2
3
- import { Transformer , Processed , Options } from '../types' ;
3
+ import type { Transformer , Processed , Options } from '../types' ;
4
4
import { getIncludePaths , importAny } from '../modules/utils' ;
5
5
6
6
let sass : Options . Sass [ 'implementation' ] ;
@@ -19,6 +19,14 @@ function getResultForResolve(result: Result): ResolveResult {
19
19
} ;
20
20
}
21
21
22
+ const tildeImporter : Importer = ( url , _prev , done ) => {
23
+ if ( url . startsWith ( '~' ) ) {
24
+ return done ( { file : url . slice ( 1 ) } ) ;
25
+ }
26
+
27
+ return done ( { file : url } ) ;
28
+ } ;
29
+
22
30
const transformer : Transformer < Options . Sass > = async ( {
23
31
content,
24
32
filename,
@@ -44,6 +52,14 @@ const transformer: Transformer<Options.Sass> = async ({
44
52
data : content ,
45
53
} ;
46
54
55
+ if ( Array . isArray ( sassOptions . importer ) ) {
56
+ sassOptions . importer . push ( tildeImporter ) ;
57
+ } else if ( sassOptions . importer == null ) {
58
+ sassOptions . importer = [ tildeImporter ] ;
59
+ } else {
60
+ sassOptions . importer = [ sassOptions . importer , tildeImporter ] ;
61
+ }
62
+
47
63
// scss errors if passed an empty string
48
64
if ( sassOptions . data . length === 0 ) {
49
65
return { code : '' } ;
0 commit comments