diff --git a/src/createWebpackLessPlugin.js b/src/createWebpackLessPlugin.js index b3089550..d19559f2 100644 --- a/src/createWebpackLessPlugin.js +++ b/src/createWebpackLessPlugin.js @@ -8,7 +8,7 @@ const trailingSlash = /[/\\]$/; // This somewhat changed in Less 3.x. Now the file name comes without the // automatically added extension whereas the extension is passed in as `options.ext`. // So, if the file name matches this regexp, we simply ignore the proposed extension. -const isModuleName = /^~[^/\\]+$/; +const isModuleName = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/; /** * Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext. @@ -88,9 +88,16 @@ function createWebpackLessPlugin(loaderContext) { let result; try { + if (isModuleName.test(filename)) { + const error = new Error(); + + error.type = 'Next'; + throw error; + } + result = await super.loadFile(filename, ...args); } catch (error) { - if (error.type !== 'File') { + if (error.type !== 'File' && error.type !== 'Next') { loaderContext.emitError(error); return Promise.reject(error); diff --git a/test/fixtures/less/import-scope.less b/test/fixtures/less/import-scope.less new file mode 100644 index 00000000..8895c90f --- /dev/null +++ b/test/fixtures/less/import-scope.less @@ -0,0 +1,6 @@ +@import "~@scope/module"; +@import "~@scope/css.css"; + +#it-works:extend(.modules-dir-scope-module) { + margin: 10px; +} diff --git a/test/fixtures/node_modules/@scope/css.css b/test/fixtures/node_modules/@scope/css.css new file mode 100644 index 00000000..6167869e --- /dev/null +++ b/test/fixtures/node_modules/@scope/css.css @@ -0,0 +1,3 @@ +.modules-dir-scope-module { + background: hotpink; +} diff --git a/test/fixtures/node_modules/@scope/module.less b/test/fixtures/node_modules/@scope/module.less new file mode 100644 index 00000000..69c76e4c --- /dev/null +++ b/test/fixtures/node_modules/@scope/module.less @@ -0,0 +1,3 @@ +.modules-dir-scope-module { + color: hotpink; +} diff --git a/test/helpers/createSpec.js b/test/helpers/createSpec.js index 79022af9..9afa6c2d 100644 --- a/test/helpers/createSpec.js +++ b/test/helpers/createSpec.js @@ -21,11 +21,15 @@ const ignore = [ ]; const lessReplacements = [ [/~some\//g, '../node_modules/some/'], + [/~@scope\//g, '../node_modules/@scope/'], [/(~)?assets\//g, '../less/'], [/~fileAlias/g, '../less/img.less'], [/~(aliased-)?some"/g, '../node_modules/some/module.less"'], ]; -const cssReplacements = [[/\.\.\/node_modules\/some\//g, '~some/']]; +const cssReplacements = [ + [/\.\.\/node_modules\/some\//g, '~some/'], + [/\.\.\/node_modules\/@scope\//g, '~@scope/'], +]; // Maps test ids on cli arguments const lessOptions = { 'source-map': [ diff --git a/test/index.test.js b/test/index.test.js index e51a4687..7595f086 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -72,6 +72,10 @@ test("should resolve all imports from node_modules using webpack's resolver", as await compileAndCompare('import-webpack'); }); +test("should resolve all imports from node_modules using webpack's resolver", async () => { + await compileAndCompare('import-scope'); +}); + test('should add all resolved imports as dependencies, including node_modules', async () => { const dependencies = [];