diff --git a/src/utils.js b/src/utils.js index 6f71b6d..6380eb2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -32,6 +32,7 @@ const MODULE_REQUEST_REGEX = /^[^?]*~/; */ function createWebpackLessPlugin(loaderContext) { const resolve = loaderContext.getResolve({ + dependencyType: "less", conditionNames: ["less", "style"], mainFields: ["less", "style", "main", "..."], mainFiles: ["index", "..."], diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 8d4cb41..901c3a5 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -525,6 +525,20 @@ exports[`loader should watch imports correctly: errors 1`] = `Array []`; exports[`loader should watch imports correctly: warnings 1`] = `Array []`; +exports[`loader should work and respect the 'resolve.byDependecy.less' option: css 1`] = ` +".a { + color: red; +} +.b { + color: red; +} +" +`; + +exports[`loader should work and respect the 'resolve.byDependecy.less' option: errors 1`] = `Array []`; + +exports[`loader should work and respect the 'resolve.byDependecy.less' option: warnings 1`] = `Array []`; + exports[`loader should work lessOptions.relativeUrls is false: css 1`] = ` ".top-import { background: red; diff --git a/test/fixtures/by-dependency.less b/test/fixtures/by-dependency.less new file mode 100644 index 0000000..58ed040 --- /dev/null +++ b/test/fixtures/by-dependency.less @@ -0,0 +1,5 @@ +@import "custom-main-files"; + +.b { + color: red +} diff --git a/test/fixtures/circular.less b/test/fixtures/circular.less new file mode 100644 index 0000000..a0dab9c --- /dev/null +++ b/test/fixtures/circular.less @@ -0,0 +1,5 @@ +@import "circular"; + +a { + color: red; +} diff --git a/test/fixtures/custom-main-files/custom.less b/test/fixtures/custom-main-files/custom.less new file mode 100644 index 0000000..e88d515 --- /dev/null +++ b/test/fixtures/custom-main-files/custom.less @@ -0,0 +1,3 @@ +.a { + color: red +} diff --git a/test/helpers/getCodeFromLess.js b/test/helpers/getCodeFromLess.js index 8b13139..3f047a3 100644 --- a/test/helpers/getCodeFromLess.js +++ b/test/helpers/getCodeFromLess.js @@ -108,6 +108,13 @@ const pathMap = { "prefer-relative", "index.less" ), + "custom-main-files": path.resolve( + __dirname, + "..", + "fixtures", + "custom-main-files", + "custom.less" + ), }; class ResolvePlugin extends less.FileManager { diff --git a/test/loader.test.js b/test/loader.test.js index c2689ee..2629e97 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -838,4 +838,43 @@ describe("loader", () => { expect(getWarnings(stats)).toMatchSnapshot("warnings"); expect(getErrors(stats)).toMatchSnapshot("errors"); }); + + // TODO bug on windows + it.skip("should work with circular imports", async () => { + const testId = "./circular.less"; + const compiler = getCompiler(testId); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle(stats, compiler); + const codeFromLess = await getCodeFromLess(testId); + + expect(codeFromBundle.css).toBe(codeFromLess.css); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + }); + + it("should work and respect the 'resolve.byDependecy.less' option", async () => { + const testId = "./by-dependency.less"; + const compiler = getCompiler( + testId, + {}, + { + resolve: { + byDependency: { + less: { + mainFiles: ["custom"], + }, + }, + }, + } + ); + const stats = await compile(compiler); + const codeFromBundle = getCodeFromBundle(stats, compiler); + const codeFromLess = await getCodeFromLess(testId); + + expect(codeFromBundle.css).toBe(codeFromLess.css); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + }); });