@@ -19,7 +19,7 @@ const matchCss = /\.css$/i;
19
19
* (based on whether the call is sync or async) because otherwise node-sass doesn't exit.
20
20
*
21
21
*/
22
- function webpackImporter ( loaderContext , resolve , includePaths ) {
22
+ function webpackImporter ( loaderContext , includePaths ) {
23
23
function dirContextFrom ( fileContext ) {
24
24
return path . dirname (
25
25
// The first file is 'stdin' when we're using the data option
@@ -32,7 +32,7 @@ function webpackImporter(loaderContext, resolve, includePaths) {
32
32
return Promise . reject ( ) ;
33
33
}
34
34
35
- const [ { context, possibleRequests } ] = resolutionMap ;
35
+ const [ { resolve , context, possibleRequests } ] = resolutionMap ;
36
36
37
37
return resolve ( context , possibleRequests [ 0 ] )
38
38
. then ( ( result ) => {
@@ -60,6 +60,22 @@ function webpackImporter(loaderContext, resolve, includePaths) {
60
60
} ) ;
61
61
}
62
62
63
+ // We can't use `loaderContext.resolve` because it resolves values from default `extensions`/`mainFields`/etc from webpack configuration
64
+ const sassResolve = loaderContext . getResolve ( {
65
+ alias : [ ] ,
66
+ aliasFields : [ ] ,
67
+ descriptionFiles : [ ] ,
68
+ extensions : [ ] ,
69
+ mainFields : [ ] ,
70
+ mainFiles : [ ] ,
71
+ modules : [ ] ,
72
+ } ) ;
73
+ const webpackResolve = loaderContext . getResolve ( {
74
+ mainFields : [ 'sass' , 'style' , 'main' , '...' ] ,
75
+ mainFiles : [ '_index' , 'index' , '...' ] ,
76
+ extensions : [ '.sass' , '.scss' , '.css' ] ,
77
+ } ) ;
78
+
63
79
return ( url , prev , done ) => {
64
80
// The order of import precedence is as follows:
65
81
//
@@ -75,11 +91,13 @@ function webpackImporter(loaderContext, resolve, includePaths) {
75
91
const resolutionMap = [ ]
76
92
. concat (
77
93
includePaths . map ( ( context ) => ( {
94
+ resolve : sassResolve ,
78
95
context,
79
96
possibleRequests : sassPossibleRequests ,
80
97
} ) )
81
98
)
82
99
. concat ( {
100
+ resolve : webpackResolve ,
83
101
context : dirContextFrom ( prev ) ,
84
102
possibleRequests : webpackPossibleRequests ,
85
103
} ) ;
0 commit comments