Skip to content

Commit da0be65

Browse files
paniuncleliushuoyan
authored and
liushuoyan
committed
fix: add onlyWebpackImporter option
1 parent 200d836 commit da0be65

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,45 @@ module.exports = {
346346
};
347347
```
348348

349+
### `onlyWebpackImporter`
350+
351+
Type:
352+
353+
```ts
354+
type onlyWebpackImporter = boolean;
355+
```
356+
357+
Default: `true`
358+
359+
Enables/Disables the only use `webpack` importer.
360+
361+
This can improve performance in some cases. Use it with caution because aliases and `@import` from [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules) will not work.
362+
363+
**webpack.config.js**
364+
365+
```js
366+
module.exports = {
367+
module: {
368+
rules: [
369+
{
370+
test: /\.less$/i,
371+
use: [
372+
"style-loader",
373+
"css-loader",
374+
{
375+
loader: "less-loader",
376+
options: {
377+
webpackImporter: true,
378+
onlyWebpackImporter: true,
379+
},
380+
},
381+
],
382+
},
383+
],
384+
},
385+
};
386+
```
387+
349388
### `implementation`
350389

351390
Type:

src/utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const MODULE_REQUEST_REGEX = /^[^?]*~/;
3030
* @returns {LessPlugin}
3131
*/
3232
function createWebpackLessPlugin(loaderContext, implementation) {
33+
const lessOptions = loaderContext.getOptions();
3334
const resolve = loaderContext.getResolve({
3435
dependencyType: "less",
3536
conditionNames: ["less", "style", "..."],
@@ -105,7 +106,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
105106
let result;
106107

107108
try {
108-
if (IS_SPECIAL_MODULE_IMPORT.test(filename)) {
109+
if (IS_SPECIAL_MODULE_IMPORT.test(filename) || lessOptions.onlyWebpackImporter) {
109110
const error = new Error();
110111

111112
error.type = "Next";

0 commit comments

Comments
 (0)