Skip to content

Commit 744112d

Browse files
fix: perf (#840)
1 parent aeb86f0 commit 744112d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ function loader(content) {
3333
: true;
3434

3535
if (shouldUseWebpackImporter) {
36-
const resolve = this.getResolve({
37-
mainFields: ['sass', 'style', 'main', '...'],
38-
mainFiles: ['_index', 'index', '...'],
39-
extensions: ['.sass', '.scss', '.css'],
40-
});
41-
4236
const { includePaths } = sassOptions;
4337

44-
sassOptions.importer.push(webpackImporter(this, resolve, includePaths));
38+
sassOptions.importer.push(webpackImporter(this, includePaths));
4539
}
4640

4741
const callback = this.async();

src/webpackImporter.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const matchCss = /\.css$/i;
1919
* (based on whether the call is sync or async) because otherwise node-sass doesn't exit.
2020
*
2121
*/
22-
function webpackImporter(loaderContext, resolve, includePaths) {
22+
function webpackImporter(loaderContext, includePaths) {
2323
function dirContextFrom(fileContext) {
2424
return path.dirname(
2525
// The first file is 'stdin' when we're using the data option
@@ -32,7 +32,7 @@ function webpackImporter(loaderContext, resolve, includePaths) {
3232
return Promise.reject();
3333
}
3434

35-
const [{ context, possibleRequests }] = resolutionMap;
35+
const [{ resolve, context, possibleRequests }] = resolutionMap;
3636

3737
return resolve(context, possibleRequests[0])
3838
.then((result) => {
@@ -60,6 +60,22 @@ function webpackImporter(loaderContext, resolve, includePaths) {
6060
});
6161
}
6262

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+
6379
return (url, prev, done) => {
6480
// The order of import precedence is as follows:
6581
//
@@ -75,11 +91,13 @@ function webpackImporter(loaderContext, resolve, includePaths) {
7591
const resolutionMap = []
7692
.concat(
7793
includePaths.map((context) => ({
94+
resolve: sassResolve,
7895
context,
7996
possibleRequests: sassPossibleRequests,
8097
}))
8198
)
8299
.concat({
100+
resolve: webpackResolve,
83101
context: dirContextFrom(prev),
84102
possibleRequests: webpackPossibleRequests,
85103
});

0 commit comments

Comments
 (0)