Skip to content

Commit 99d80bd

Browse files
feat: supported by dependency (#407)
1 parent 3cb1678 commit 99d80bd

File tree

7 files changed

+74
-0
lines changed

7 files changed

+74
-0
lines changed

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const MODULE_REQUEST_REGEX = /^[^?]*~/;
3232
*/
3333
function createWebpackLessPlugin(loaderContext) {
3434
const resolve = loaderContext.getResolve({
35+
dependencyType: "less",
3536
conditionNames: ["less", "style"],
3637
mainFields: ["less", "style", "main", "..."],
3738
mainFiles: ["index", "..."],

test/__snapshots__/loader.test.js.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,20 @@ exports[`loader should watch imports correctly: errors 1`] = `Array []`;
525525
526526
exports[`loader should watch imports correctly: warnings 1`] = `Array []`;
527527
528+
exports[`loader should work and respect the 'resolve.byDependecy.less' option: css 1`] = `
529+
".a {
530+
color: red;
531+
}
532+
.b {
533+
color: red;
534+
}
535+
"
536+
`;
537+
538+
exports[`loader should work and respect the 'resolve.byDependecy.less' option: errors 1`] = `Array []`;
539+
540+
exports[`loader should work and respect the 'resolve.byDependecy.less' option: warnings 1`] = `Array []`;
541+
528542
exports[`loader should work lessOptions.relativeUrls is false: css 1`] = `
529543
".top-import {
530544
background: red;

test/fixtures/by-dependency.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "custom-main-files";
2+
3+
.b {
4+
color: red
5+
}

test/fixtures/circular.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import "circular";
2+
3+
a {
4+
color: red;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.a {
2+
color: red
3+
}

test/helpers/getCodeFromLess.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ const pathMap = {
108108
"prefer-relative",
109109
"index.less"
110110
),
111+
"custom-main-files": path.resolve(
112+
__dirname,
113+
"..",
114+
"fixtures",
115+
"custom-main-files",
116+
"custom.less"
117+
),
111118
};
112119

113120
class ResolvePlugin extends less.FileManager {

test/loader.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,4 +838,43 @@ describe("loader", () => {
838838
expect(getWarnings(stats)).toMatchSnapshot("warnings");
839839
expect(getErrors(stats)).toMatchSnapshot("errors");
840840
});
841+
842+
// TODO bug on windows
843+
it.skip("should work with circular imports", async () => {
844+
const testId = "./circular.less";
845+
const compiler = getCompiler(testId);
846+
const stats = await compile(compiler);
847+
const codeFromBundle = getCodeFromBundle(stats, compiler);
848+
const codeFromLess = await getCodeFromLess(testId);
849+
850+
expect(codeFromBundle.css).toBe(codeFromLess.css);
851+
expect(codeFromBundle.css).toMatchSnapshot("css");
852+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
853+
expect(getErrors(stats)).toMatchSnapshot("errors");
854+
});
855+
856+
it("should work and respect the 'resolve.byDependecy.less' option", async () => {
857+
const testId = "./by-dependency.less";
858+
const compiler = getCompiler(
859+
testId,
860+
{},
861+
{
862+
resolve: {
863+
byDependency: {
864+
less: {
865+
mainFiles: ["custom"],
866+
},
867+
},
868+
},
869+
}
870+
);
871+
const stats = await compile(compiler);
872+
const codeFromBundle = getCodeFromBundle(stats, compiler);
873+
const codeFromLess = await getCodeFromLess(testId);
874+
875+
expect(codeFromBundle.css).toBe(codeFromLess.css);
876+
expect(codeFromBundle.css).toMatchSnapshot("css");
877+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
878+
expect(getErrors(stats)).toMatchSnapshot("errors");
879+
});
841880
});

0 commit comments

Comments
 (0)