Skip to content

Commit 5d31444

Browse files
fix: prefer scss, sass and css extension in resolving
1 parent 2adcca3 commit 5d31444

File tree

10 files changed

+29
-56
lines changed

10 files changed

+29
-56
lines changed

lib/loader.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const path = require('path');
44

55
const async = require('neo-async');
6-
const pify = require('pify');
76
const semver = require('semver');
87

98
const formatSassError = require('./formatSassError');
@@ -35,14 +34,19 @@ function sassLoader(content) {
3534
);
3635
}
3736

37+
let { resolve } = this;
38+
39+
// Supported since v4.27.0
40+
if (this.getResolve) {
41+
resolve = this.getResolve({
42+
extensions: ['.scss', '.sass', '.css'],
43+
});
44+
}
45+
3846
const options = normalizeOptions(
3947
this,
4048
content,
41-
webpackImporter(
42-
resourcePath,
43-
pify(this.resolve.bind(this)),
44-
addNormalizedDependency
45-
)
49+
webpackImporter(resourcePath, resolve, addNormalizedDependency)
4650
);
4751

4852
// Skip empty files, otherwise it will stop webpack, see issue #21

package-lock.json

+5-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"loader-utils": "^1.0.1",
3232
"lodash.tail": "^4.1.1",
3333
"neo-async": "^2.5.0",
34-
"pify": "^4.0.1",
3534
"semver": "^5.5.0"
3635
},
3736
"devDependencies": {

test/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ implementations.forEach((implementation) => {
295295
// This number needs to be updated if imports.scss or any dependency of that changes.
296296
// Node Sass includes a duplicate entry, Dart Sass does not.
297297
sourceMap.sources.should.have.length(
298-
implementation === nodeSass ? 11 : 10
298+
implementation === nodeSass ? 12 : 11
299299
);
300300
sourceMap.sources.forEach((sourcePath) =>
301301
fs.existsSync(path.resolve(sourceMap.sourceRoot, sourcePath))

test/node_modules/@org/style.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/@org/style.scss

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/scss/style.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/node_modules/scss/style.scss

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/sass/imports.sass

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@
2424
@import ~module
2525
/* @import ~another */
2626
@import ~another
27+
// Should prefer `scss`
28+
@import "~@org/style"

test/scss/imports.scss

+3
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@
2424
@import "~module";
2525
/* @import "~another"; */
2626
@import "~another";
27+
/* @import "~@org/style"; */
28+
// Should prefer `scss`
29+
@import "~@org/style";

0 commit comments

Comments
 (0)