Skip to content

Commit 2c3a23a

Browse files
fix: resolution logic
1 parent 3d01b82 commit 2c3a23a

File tree

11 files changed

+70
-0
lines changed

11 files changed

+70
-0
lines changed

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function createWebpackLessPlugin(loaderContext) {
2424
mainFields: ['less', 'style', 'main', '...'],
2525
mainFiles: ['index', '...'],
2626
extensions: ['.less', '.css'],
27+
restrictions: [/\.(le|c)ss$/i],
2728
});
2829

2930
class WebpackFileManager extends less.FileManager {

test/__snapshots__/loader.test.js.snap

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ exports[`loader should not alter the original options object: errors 1`] = `Arra
139139
140140
exports[`loader should not alter the original options object: warnings 1`] = `Array []`;
141141
142+
exports[`loader should not resolve when resolve.restrictions no passed: errors 1`] = `
143+
Array [
144+
"ModuleBuildError: Module build failed (from \`replaced original path\`):
145+
",
146+
]
147+
`;
148+
149+
exports[`loader should not resolve when resolve.restrictions no passed: warnings 1`] = `Array []`;
150+
142151
exports[`loader should not to disable webpack's resolver by passing an empty paths array: css 1`] = `
143152
".img {
144153
background: url(some/img.jpg);
@@ -179,6 +188,20 @@ exports[`loader should not try to resolve CSS imports with URLs: errors 1`] = `A
179188
180189
exports[`loader should not try to resolve CSS imports with URLs: warnings 1`] = `Array []`;
181190
191+
exports[`loader should prefer a main file with "less" extension over main field with js file: css 1`] = `
192+
".modules-dir-some-module {
193+
color: hotpink;
194+
}
195+
.some-class {
196+
background: hotpink;
197+
}
198+
"
199+
`;
200+
201+
exports[`loader should prefer a main file with "less" extension over main field with js file: errors 1`] = `Array []`;
202+
203+
exports[`loader should prefer a main file with "less" extension over main field with js file: warnings 1`] = `Array []`;
204+
182205
exports[`loader should provide a useful error message if the import could not be found: errors 1`] = `
183206
Array [
184207
"ModuleBuildError: Module build failed (from \`replaced original path\`):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "~some-illegal-2";
2+
3+
.some-class {
4+
background: hotpink;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "~some-illegal";
2+
3+
.some-class {
4+
background: hotpink;
5+
}

test/fixtures/node_modules/some-illegal-2/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/some-illegal-2/index.less

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/some-illegal-2/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/some-illegal/module.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/some-illegal/module.less

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/some-illegal/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)