less-loader 12.3.0 → 12.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -40
- package/dist/index.js +9 -9
- package/dist/options.json +6 -6
- package/dist/utils.js +15 -23
- package/package.json +50 -41
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
# less-loader
|
|
15
15
|
|
|
16
|
-
A Less loader for webpack
|
|
16
|
+
A Less loader for webpack that compiles Less files into CSS.
|
|
17
17
|
|
|
18
18
|
## Getting Started
|
|
19
19
|
|
|
@@ -35,7 +35,7 @@ or
|
|
|
35
35
|
pnpm add -D less less-loader
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Then add the loader to your `webpack`
|
|
38
|
+
Then add the loader to your `webpack` configuration. For example:
|
|
39
39
|
|
|
40
40
|
**webpack.config.js**
|
|
41
41
|
|
|
@@ -57,7 +57,7 @@ module.exports = {
|
|
|
57
57
|
};
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
Finally, run `webpack` using the method you normally use (e.g., via CLI or an npm script).
|
|
61
61
|
|
|
62
62
|
## Options
|
|
63
63
|
|
|
@@ -72,17 +72,21 @@ And run `webpack` via your preferred method.
|
|
|
72
72
|
|
|
73
73
|
Type:
|
|
74
74
|
|
|
75
|
+
<!-- eslint-skip -->
|
|
76
|
+
|
|
75
77
|
```ts
|
|
76
78
|
type lessOptions = import('less').options | ((loaderContext: LoaderContext) => import('less').options})
|
|
77
79
|
```
|
|
78
80
|
|
|
79
81
|
Default: `{ relativeUrls: true }`
|
|
80
82
|
|
|
81
|
-
You can pass any Less specific options to the `less-loader` through the `lessOptions` property in the [loader options](https://webpack.js.org/configuration/module/#ruleoptions--rulequery). See the [Less documentation](http://lesscss.org/usage/#command-line-usage-options) for all available options in dash-case.
|
|
83
|
+
You can pass any Less specific options to the `less-loader` through the `lessOptions` property in the [loader options](https://webpack.js.org/configuration/module/#ruleoptions--rulequery). See the [Less documentation](http://lesscss.org/usage/#command-line-usage-options) for all available options in dash-case.
|
|
84
|
+
|
|
85
|
+
Since we're passing these options to Less programmatically, you need to pass them in camelCase here:
|
|
82
86
|
|
|
83
87
|
#### `object`
|
|
84
88
|
|
|
85
|
-
Use an object to pass options
|
|
89
|
+
Use an object to pass options directly to Less.
|
|
86
90
|
|
|
87
91
|
**webpack.config.js**
|
|
88
92
|
|
|
@@ -116,7 +120,7 @@ module.exports = {
|
|
|
116
120
|
|
|
117
121
|
#### `function`
|
|
118
122
|
|
|
119
|
-
Allows setting the options
|
|
123
|
+
Allows setting the Less options dynamically based on the loader context.
|
|
120
124
|
|
|
121
125
|
```js
|
|
122
126
|
module.exports = {
|
|
@@ -166,10 +170,10 @@ type additionalData =
|
|
|
166
170
|
|
|
167
171
|
Default: `undefined`
|
|
168
172
|
|
|
169
|
-
Prepends
|
|
173
|
+
Prepends or Appends `Less` code to the actual entry file.
|
|
170
174
|
In this case, the `less-loader` will not override the source but just **prepend** the entry's content.
|
|
171
175
|
|
|
172
|
-
This is especially useful when some of your Less variables depend on the environment
|
|
176
|
+
This is especially useful when some of your Less variables depend on the environment.
|
|
173
177
|
|
|
174
178
|
> Since you're injecting code, this will break the source mappings in your entry file. Often there's a simpler solution than this, like multiple Less entry files.
|
|
175
179
|
|
|
@@ -219,10 +223,10 @@ module.exports = {
|
|
|
219
223
|
const relativePath = path.relative(rootContext, resourcePath);
|
|
220
224
|
|
|
221
225
|
if (relativePath === "styles/foo.less") {
|
|
222
|
-
return
|
|
226
|
+
return `@value: 100px;${content}`;
|
|
223
227
|
}
|
|
224
228
|
|
|
225
|
-
return
|
|
229
|
+
return `@value: 200px;${content}`;
|
|
226
230
|
},
|
|
227
231
|
},
|
|
228
232
|
},
|
|
@@ -253,10 +257,10 @@ module.exports = {
|
|
|
253
257
|
const relativePath = path.relative(rootContext, resourcePath);
|
|
254
258
|
|
|
255
259
|
if (relativePath === "styles/foo.less") {
|
|
256
|
-
return
|
|
260
|
+
return `@value: 100px;${content}`;
|
|
257
261
|
}
|
|
258
262
|
|
|
259
|
-
return
|
|
263
|
+
return `@value: 200px;${content}`;
|
|
260
264
|
},
|
|
261
265
|
},
|
|
262
266
|
},
|
|
@@ -277,7 +281,8 @@ type sourceMap = boolean;
|
|
|
277
281
|
|
|
278
282
|
Default: depends on the `compiler.devtool` value
|
|
279
283
|
|
|
280
|
-
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
|
|
284
|
+
By default generation of source maps depends on the [`devtool`](https://webpack.js.org/configuration/devtool/) option.
|
|
285
|
+
All values enable source map generation except `eval` and `false` value.
|
|
281
286
|
|
|
282
287
|
**webpack.config.js**
|
|
283
288
|
|
|
@@ -318,7 +323,7 @@ type webpackImporter = boolean | "only";
|
|
|
318
323
|
|
|
319
324
|
Default: `true`
|
|
320
325
|
|
|
321
|
-
Enables
|
|
326
|
+
Enables or disables the default `webpack` importer.
|
|
322
327
|
|
|
323
328
|
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.
|
|
324
329
|
|
|
@@ -354,7 +359,7 @@ Type:
|
|
|
354
359
|
type implementation = object | string;
|
|
355
360
|
```
|
|
356
361
|
|
|
357
|
-
> less-loader compatible with Less 3 and 4 versions
|
|
362
|
+
> less-loader compatible with both Less 3 and 4 versions
|
|
358
363
|
|
|
359
364
|
The special `implementation` option determines which implementation of Less to use. Overrides the locally installed `peerDependency` version of `less`.
|
|
360
365
|
|
|
@@ -362,6 +367,8 @@ The special `implementation` option determines which implementation of Less to u
|
|
|
362
367
|
|
|
363
368
|
#### `object`
|
|
364
369
|
|
|
370
|
+
Example using a Less instance:
|
|
371
|
+
|
|
365
372
|
**webpack.config.js**
|
|
366
373
|
|
|
367
374
|
```js
|
|
@@ -388,6 +395,8 @@ module.exports = {
|
|
|
388
395
|
|
|
389
396
|
#### `string`
|
|
390
397
|
|
|
398
|
+
Example using a resolved Less module path:
|
|
399
|
+
|
|
391
400
|
**webpack.config.js**
|
|
392
401
|
|
|
393
402
|
```js
|
|
@@ -422,7 +431,7 @@ type lessLogAsWarnOrErr = boolean;
|
|
|
422
431
|
|
|
423
432
|
Default: `false`
|
|
424
433
|
|
|
425
|
-
`Less` warnings and errors will be webpack warnings and errors,
|
|
434
|
+
`Less` warnings and errors will be treated as webpack warnings and errors, instead of being logged silently.
|
|
426
435
|
|
|
427
436
|
**warning.less**
|
|
428
437
|
|
|
@@ -432,7 +441,7 @@ div {
|
|
|
432
441
|
}
|
|
433
442
|
```
|
|
434
443
|
|
|
435
|
-
If `lessLogAsWarnOrErr` is set to `false` it will be just a log and webpack will compile successfully, but if you set this option to `true` webpack will compile fail with a warning.
|
|
444
|
+
If `lessLogAsWarnOrErr` is set to `false` it will be just a log and webpack will compile successfully, but if you set this option to `true` webpack will compile fail with a warning(or error), and can break the build if configured accordingly.
|
|
436
445
|
|
|
437
446
|
**webpack.config.js**
|
|
438
447
|
|
|
@@ -462,7 +471,7 @@ module.exports = {
|
|
|
462
471
|
|
|
463
472
|
### Normal usage
|
|
464
473
|
|
|
465
|
-
Chain the `less-loader` with
|
|
474
|
+
Chain the `less-loader` with [`css-loader`](https://github.com/webpack/css-loader) and [`style-loader`](https://github.com/webpack/style-loader) to immediately apply all styles to the DOM.
|
|
466
475
|
|
|
467
476
|
**webpack.config.js**
|
|
468
477
|
|
|
@@ -474,13 +483,13 @@ module.exports = {
|
|
|
474
483
|
test: /\.less$/i,
|
|
475
484
|
use: [
|
|
476
485
|
{
|
|
477
|
-
loader: "style-loader", //
|
|
486
|
+
loader: "style-loader", // Creates style nodes from JS strings
|
|
478
487
|
},
|
|
479
488
|
{
|
|
480
|
-
loader: "css-loader", //
|
|
489
|
+
loader: "css-loader", // Translates CSS into CommonJS
|
|
481
490
|
},
|
|
482
491
|
{
|
|
483
|
-
loader: "less-loader", //
|
|
492
|
+
loader: "less-loader", // Compiles Less to CSS
|
|
484
493
|
},
|
|
485
494
|
],
|
|
486
495
|
},
|
|
@@ -529,7 +538,7 @@ If you want to edit the original Less files inside Chrome, [there's a good blog
|
|
|
529
538
|
|
|
530
539
|
### In production
|
|
531
540
|
|
|
532
|
-
Usually, it's recommended to extract the style sheets into a dedicated file in production using the [MiniCssExtractPlugin](https://github.com/webpack
|
|
541
|
+
Usually, it's recommended to extract the style sheets into a dedicated file in production using the [MiniCssExtractPlugin](https://github.com/webpack/mini-css-extract-plugin). This way your styles are not dependent on JavaScript, improving performance and cacheability.
|
|
533
542
|
|
|
534
543
|
### Imports
|
|
535
544
|
|
|
@@ -545,7 +554,7 @@ Thus you can import your Less modules from `node_modules`.
|
|
|
545
554
|
@import "bootstrap/less/bootstrap";
|
|
546
555
|
```
|
|
547
556
|
|
|
548
|
-
Using `~` is deprecated and can be removed from your code (**we recommend it**), but we still support it for historical reasons.
|
|
557
|
+
Using `~` prefix (e.g., @import "~bootstrap/less/bootstrap";) is deprecated and can be removed from your code (**we recommend it**), but we still support it for historical reasons.
|
|
549
558
|
Why you can removed it? The loader will first try to resolve `@import` as relative, if it cannot be resolved, the loader will try to resolve `@import` inside [`node_modules`](https://webpack.js.org/configuration/resolve/#resolvemodules).
|
|
550
559
|
|
|
551
560
|
Default resolver options can be modified by [`resolve.byDependency`](https://webpack.js.org/configuration/resolve/#resolvebydependency):
|
|
@@ -610,10 +619,12 @@ module.exports = {
|
|
|
610
619
|
|
|
611
620
|
### Plugins
|
|
612
621
|
|
|
613
|
-
In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the `plugins` option like this:
|
|
622
|
+
In order to use [Less plugins](http://lesscss.org/usage/#plugins), simply set the `plugins` option like this:
|
|
614
623
|
|
|
615
624
|
**webpack.config.js**
|
|
616
625
|
|
|
626
|
+
<!-- eslint-skip -->
|
|
627
|
+
|
|
617
628
|
```js
|
|
618
629
|
const CleanCSSPlugin = require('less-plugin-clean-css');
|
|
619
630
|
|
|
@@ -635,38 +646,44 @@ module.exports = {
|
|
|
635
646
|
|
|
636
647
|
> [!NOTE]
|
|
637
648
|
>
|
|
638
|
-
> Access to the [loader context](https://webpack.js.org/api/loaders/#the-loader-context) inside
|
|
649
|
+
> Access to the [loader context](https://webpack.js.org/api/loaders/#the-loader-context) inside a custom plugin can be done using the `pluginManager.webpackLoaderContext` property.
|
|
639
650
|
|
|
640
651
|
```js
|
|
641
652
|
module.exports = {
|
|
642
|
-
install
|
|
643
|
-
functions.add(
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
653
|
+
install(less, pluginManager, functions) {
|
|
654
|
+
functions.add(
|
|
655
|
+
"pi",
|
|
656
|
+
() =>
|
|
657
|
+
// Loader context is available in `pluginManager.webpackLoaderContext`
|
|
658
|
+
|
|
659
|
+
Math.PI,
|
|
660
|
+
);
|
|
648
661
|
},
|
|
649
662
|
};
|
|
650
663
|
```
|
|
651
664
|
|
|
652
665
|
### Extracting style sheets
|
|
653
666
|
|
|
654
|
-
Bundling CSS with webpack has some nice advantages like referencing images and fonts with hashed urls or [
|
|
667
|
+
Bundling CSS with webpack has some nice advantages like referencing images and fonts with hashed urls or [Hot Module Replacement(HMR)](https://webpack.js.org/concepts/hot-module-replacement/) in development.
|
|
668
|
+
|
|
669
|
+
In production, on the other hand, it's not a good idea to apply your style sheets depending on JS execution. Rendering may be delayed or even a [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) might be visible. Thus it's often still better to have them as separate files in your final production build.
|
|
655
670
|
|
|
656
671
|
There are two possibilities to extract a style sheet from the bundle:
|
|
657
672
|
|
|
658
673
|
- [`extract-loader`](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
|
|
659
|
-
- [`MiniCssExtractPlugin`](https://github.com/webpack
|
|
674
|
+
- [`MiniCssExtractPlugin`](https://github.com/webpack/mini-css-extract-plugin) (more complex, but works in all use-cases)
|
|
660
675
|
|
|
661
676
|
### CSS modules gotcha
|
|
662
677
|
|
|
663
|
-
There is a known problem
|
|
678
|
+
There is a known problem when using Less with [CSS modules](https://github.com/css-modules/css-modules) regarding relative file paths in `url(...)` statements.
|
|
679
|
+
[See this issue for an explanation](https://github.com/webpack/less-loader/issues/109#issuecomment-253797335).
|
|
664
680
|
|
|
665
681
|
## Contributing
|
|
666
682
|
|
|
667
|
-
|
|
683
|
+
We welcome all contributions!
|
|
684
|
+
If you're new here, please take a moment to review our contributing guidelines before submitting issues or pull requests.
|
|
668
685
|
|
|
669
|
-
[CONTRIBUTING](
|
|
686
|
+
[CONTRIBUTING](https://github.com/webpack/less-loader?tab=contributing-ov-file#contributing)
|
|
670
687
|
|
|
671
688
|
## License
|
|
672
689
|
|
|
@@ -676,10 +693,10 @@ Please take a moment to read our contributing guidelines if you haven't yet done
|
|
|
676
693
|
[npm-url]: https://npmjs.com/package/less-loader
|
|
677
694
|
[node]: https://img.shields.io/node/v/less-loader.svg
|
|
678
695
|
[node-url]: https://nodejs.org
|
|
679
|
-
[tests]: https://github.com/webpack
|
|
680
|
-
[tests-url]: https://github.com/webpack
|
|
681
|
-
[cover]: https://codecov.io/gh/webpack
|
|
682
|
-
[cover-url]: https://codecov.io/gh/webpack
|
|
696
|
+
[tests]: https://github.com/webpack/less-loader/workflows/less-loader/badge.svg
|
|
697
|
+
[tests-url]: https://github.com/webpack/less-loader/actions
|
|
698
|
+
[cover]: https://codecov.io/gh/webpack/less-loader/branch/main/graph/badge.svg
|
|
699
|
+
[cover-url]: https://codecov.io/gh/webpack/less-loader
|
|
683
700
|
[discussion]: https://img.shields.io/github/discussions/webpack/webpack
|
|
684
701
|
[discussion-url]: https://github.com/webpack/webpack/discussions
|
|
685
702
|
[size]: https://packagephobia.now.sh/badge?p=less-loader
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
8
8
|
var _options = _interopRequireDefault(require("./options.json"));
|
|
9
9
|
var _utils = require("./utils");
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -66,8 +66,8 @@ async function lessLoader(source) {
|
|
|
66
66
|
} catch (error) {
|
|
67
67
|
if (error.filename) {
|
|
68
68
|
// `less` returns forward slashes on windows when `webpack` resolver return an absolute windows path in `WebpackFileManager`
|
|
69
|
-
// Ref: https://github.com/webpack
|
|
70
|
-
this.addDependency(
|
|
69
|
+
// Ref: https://github.com/webpack/less-loader/issues/357
|
|
70
|
+
this.addDependency(_nodePath.default.normalize(error.filename));
|
|
71
71
|
}
|
|
72
72
|
callback((0, _utils.errorFactory)(error));
|
|
73
73
|
return;
|
|
@@ -81,20 +81,20 @@ async function lessLoader(source) {
|
|
|
81
81
|
css,
|
|
82
82
|
imports
|
|
83
83
|
} = result;
|
|
84
|
-
|
|
84
|
+
for (const item of imports) {
|
|
85
85
|
if ((0, _utils.isUnsupportedUrl)(item)) {
|
|
86
|
-
|
|
86
|
+
continue;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// `less` return forward slashes on windows when `webpack` resolver return an absolute windows path in `WebpackFileManager`
|
|
90
|
-
// Ref: https://github.com/webpack
|
|
91
|
-
const normalizedItem =
|
|
90
|
+
// Ref: https://github.com/webpack/less-loader/issues/357
|
|
91
|
+
const normalizedItem = _nodePath.default.normalize(item);
|
|
92
92
|
|
|
93
93
|
// Custom `importer` can return only `contents` so item will be relative
|
|
94
|
-
if (
|
|
94
|
+
if (_nodePath.default.isAbsolute(normalizedItem)) {
|
|
95
95
|
this.addDependency(normalizedItem);
|
|
96
96
|
}
|
|
97
|
-
}
|
|
97
|
+
}
|
|
98
98
|
let map = typeof result.map === "string" ? JSON.parse(result.map) : result.map;
|
|
99
99
|
if (map && useSourceMap) {
|
|
100
100
|
map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
|
package/dist/options.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"properties": {
|
|
5
5
|
"lessOptions": {
|
|
6
6
|
"description": "Options to pass through to `Less`.",
|
|
7
|
-
"link": "https://github.com/webpack
|
|
7
|
+
"link": "https://github.com/webpack/less-loader#lessoptions",
|
|
8
8
|
"anyOf": [
|
|
9
9
|
{
|
|
10
10
|
"type": "object",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"additionalData": {
|
|
19
19
|
"description": "Prepends/Appends `Less` code to the actual entry file.",
|
|
20
|
-
"link": "https://github.com/webpack
|
|
20
|
+
"link": "https://github.com/webpack/less-loader#additionalData",
|
|
21
21
|
"anyOf": [
|
|
22
22
|
{
|
|
23
23
|
"type": "string"
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"sourceMap": {
|
|
31
31
|
"description": "Enables/Disables generation of source maps.",
|
|
32
|
-
"link": "https://github.com/webpack
|
|
32
|
+
"link": "https://github.com/webpack/less-loader#sourcemap",
|
|
33
33
|
"type": "boolean"
|
|
34
34
|
},
|
|
35
35
|
"webpackImporter": {
|
|
36
36
|
"description": "Enables/Disables default `webpack` importer.",
|
|
37
|
-
"link": "https://github.com/webpack
|
|
37
|
+
"link": "https://github.com/webpack/less-loader#webpackimporter",
|
|
38
38
|
"anyOf": [
|
|
39
39
|
{
|
|
40
40
|
"type": "boolean"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"implementation": {
|
|
49
49
|
"description": "The implementation of the `Less` to be used.",
|
|
50
|
-
"link": "https://github.com/webpack
|
|
50
|
+
"link": "https://github.com/webpack/less-loader#implementation",
|
|
51
51
|
"anyOf": [
|
|
52
52
|
{
|
|
53
53
|
"type": "string"
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"lessLogAsWarnOrErr": {
|
|
61
61
|
"description": "Less warnings and errors will be webpack warnings or errors.",
|
|
62
|
-
"link": "https://github.com/webpack
|
|
62
|
+
"link": "https://github.com/webpack/less-loader#lesslogaswarnorerr",
|
|
63
63
|
"type": "boolean"
|
|
64
64
|
}
|
|
65
65
|
},
|
package/dist/utils.js
CHANGED
|
@@ -8,9 +8,8 @@ exports.getLessImplementation = getLessImplementation;
|
|
|
8
8
|
exports.getLessOptions = getLessOptions;
|
|
9
9
|
exports.isUnsupportedUrl = isUnsupportedUrl;
|
|
10
10
|
exports.normalizeSourceMap = normalizeSourceMap;
|
|
11
|
-
var
|
|
11
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
/* eslint-disable class-methods-use-this */
|
|
14
13
|
const trailingSlash = /[/\\]$/;
|
|
15
14
|
|
|
16
15
|
// This somewhat changed in Less 3.x. Now the file name comes without the
|
|
@@ -83,7 +82,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
83
82
|
}
|
|
84
83
|
async resolveRequests(context, possibleRequests) {
|
|
85
84
|
if (possibleRequests.length === 0) {
|
|
86
|
-
|
|
85
|
+
throw new Error("No possible requests to resolve");
|
|
87
86
|
}
|
|
88
87
|
let result;
|
|
89
88
|
try {
|
|
@@ -101,26 +100,26 @@ function createWebpackLessPlugin(loaderContext, implementation) {
|
|
|
101
100
|
let result;
|
|
102
101
|
try {
|
|
103
102
|
if (IS_SPECIAL_MODULE_IMPORT.test(filename) || lessOptions.webpackImporter === "only") {
|
|
104
|
-
const error = new Error();
|
|
103
|
+
const error = new Error("Next");
|
|
105
104
|
error.type = "Next";
|
|
106
105
|
throw error;
|
|
107
106
|
}
|
|
108
107
|
result = await super.loadFile(filename, ...args);
|
|
109
108
|
} catch (error) {
|
|
110
109
|
if (error.type !== "File" && error.type !== "Next") {
|
|
111
|
-
|
|
110
|
+
throw error;
|
|
112
111
|
}
|
|
113
112
|
try {
|
|
114
113
|
result = await this.resolveFilename(filename, ...args);
|
|
115
|
-
} catch (
|
|
116
|
-
error.message = `Less resolver error:\n${error.message}\n\n` + `Webpack resolver error details:\n${
|
|
117
|
-
|
|
114
|
+
} catch (err) {
|
|
115
|
+
error.message = `Less resolver error:\n${error.message}\n\n` + `Webpack resolver error details:\n${err.details}\n\n` + `Webpack resolver error missing:\n${err.missing}\n\n`;
|
|
116
|
+
throw error;
|
|
118
117
|
}
|
|
119
118
|
loaderContext.addDependency(result);
|
|
120
119
|
return super.loadFile(result, ...args);
|
|
121
120
|
}
|
|
122
|
-
const absoluteFilename =
|
|
123
|
-
loaderContext.addDependency(
|
|
121
|
+
const absoluteFilename = _nodePath.default.isAbsolute(result.filename) ? result.filename : _nodePath.default.resolve(".", result.filename);
|
|
122
|
+
loaderContext.addDependency(_nodePath.default.normalize(absoluteFilename));
|
|
124
123
|
return result;
|
|
125
124
|
}
|
|
126
125
|
}
|
|
@@ -149,14 +148,13 @@ function getLessOptions(loaderContext, loaderOptions, implementation) {
|
|
|
149
148
|
filename: loaderContext.resourcePath,
|
|
150
149
|
...options
|
|
151
150
|
};
|
|
152
|
-
const plugins = lessOptions.plugins
|
|
151
|
+
const plugins = [...lessOptions.plugins];
|
|
153
152
|
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" || loaderOptions.webpackImporter === "only" ? loaderOptions.webpackImporter : true;
|
|
154
153
|
if (shouldUseWebpackImporter) {
|
|
155
154
|
plugins.unshift(createWebpackLessPlugin(loaderContext, implementation));
|
|
156
155
|
}
|
|
157
156
|
plugins.unshift({
|
|
158
157
|
install(lessProcessor, pluginManager) {
|
|
159
|
-
// eslint-disable-next-line no-param-reassign
|
|
160
158
|
pluginManager.webpackLoaderContext = loaderContext;
|
|
161
159
|
lessOptions.pluginManager = pluginManager;
|
|
162
160
|
}
|
|
@@ -179,27 +177,21 @@ function normalizeSourceMap(map) {
|
|
|
179
177
|
|
|
180
178
|
// map.file is an optional property that provides the output filename.
|
|
181
179
|
// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
|
|
182
|
-
// eslint-disable-next-line no-param-reassign
|
|
183
|
-
delete newMap.file;
|
|
184
180
|
|
|
185
|
-
|
|
181
|
+
delete newMap.file;
|
|
186
182
|
newMap.sourceRoot = "";
|
|
187
183
|
|
|
188
184
|
// `less` returns POSIX paths, that's why we need to transform them back to native paths.
|
|
189
|
-
|
|
190
|
-
newMap.sources = newMap.sources.map(source =>
|
|
185
|
+
|
|
186
|
+
newMap.sources = newMap.sources.map(source => _nodePath.default.normalize(source));
|
|
191
187
|
return newMap;
|
|
192
188
|
}
|
|
193
189
|
function getLessImplementation(loaderContext, implementation) {
|
|
194
190
|
let resolvedImplementation = implementation;
|
|
195
191
|
if (!implementation || typeof implementation === "string") {
|
|
196
192
|
const lessImplPkg = implementation || "less";
|
|
197
|
-
|
|
198
|
-
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
199
193
|
resolvedImplementation = require(lessImplPkg);
|
|
200
194
|
}
|
|
201
|
-
|
|
202
|
-
// eslint-disable-next-line consistent-return
|
|
203
195
|
return resolvedImplementation;
|
|
204
196
|
}
|
|
205
197
|
function getFileExcerptIfPossible(error) {
|
|
@@ -211,11 +203,11 @@ function getFileExcerptIfPossible(error) {
|
|
|
211
203
|
if (typeof excerpt[0] === "undefined") {
|
|
212
204
|
excerpt.shift();
|
|
213
205
|
}
|
|
214
|
-
excerpt.push(`${
|
|
206
|
+
excerpt.push(`${" ".repeat(column)}^`);
|
|
215
207
|
return excerpt;
|
|
216
208
|
}
|
|
217
209
|
function errorFactory(error) {
|
|
218
|
-
const message = ["\n", ...getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), error.filename ? ` Error in ${
|
|
210
|
+
const message = ["\n", ...getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), error.filename ? ` Error in ${_nodePath.default.normalize(error.filename)} (line ${error.line}, column ${error.column})` : ""].join("\n");
|
|
219
211
|
const obj = new Error(message, {
|
|
220
212
|
cause: error
|
|
221
213
|
});
|
package/package.json
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "less-loader",
|
|
3
|
-
"version": "12.3.
|
|
3
|
+
"version": "12.3.1",
|
|
4
4
|
"description": "A Less loader for webpack. Compiles Less to CSS.",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"webpack",
|
|
7
|
+
"loader",
|
|
8
|
+
"less",
|
|
9
|
+
"lesscss",
|
|
10
|
+
"less.js",
|
|
11
|
+
"css",
|
|
12
|
+
"preprocessor"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/webpack/less-loader",
|
|
15
|
+
"bugs": "https://github.com/webpack/less-loader/issues",
|
|
16
|
+
"repository": "webpack/less-loader",
|
|
10
17
|
"funding": {
|
|
11
18
|
"type": "opencollective",
|
|
12
19
|
"url": "https://opencollective.com/webpack"
|
|
13
20
|
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Johannes Ewald @jhnns",
|
|
14
23
|
"main": "dist/cjs.js",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
18
27
|
"scripts": {
|
|
19
28
|
"start": "npm run build -- -w",
|
|
20
29
|
"clean": "del-cli dist",
|
|
21
30
|
"prebuild": "npm run clean",
|
|
22
31
|
"build": "cross-env NODE_ENV=production babel src -d dist --copy-files",
|
|
23
|
-
"commitlint": "commitlint --from=
|
|
32
|
+
"commitlint": "commitlint --from=main",
|
|
24
33
|
"security": "npm audit --production",
|
|
25
34
|
"lint:prettier": "prettier --cache --list-different .",
|
|
26
35
|
"lint:js": "eslint --cache .",
|
|
@@ -37,39 +46,31 @@
|
|
|
37
46
|
"prepare": "husky && npm run build",
|
|
38
47
|
"release": "standard-version"
|
|
39
48
|
},
|
|
40
|
-
"files": [
|
|
41
|
-
"dist"
|
|
42
|
-
],
|
|
43
|
-
"peerDependencies": {
|
|
44
|
-
"@rspack/core": "0.x || 1.x",
|
|
45
|
-
"less": "^3.5.0 || ^4.0.0",
|
|
46
|
-
"webpack": "^5.0.0"
|
|
47
|
-
},
|
|
48
|
-
"peerDependenciesMeta": {
|
|
49
|
-
"@rspack/core": {
|
|
50
|
-
"optional": true
|
|
51
|
-
},
|
|
52
|
-
"webpack": {
|
|
53
|
-
"optional": true
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
49
|
"devDependencies": {
|
|
57
50
|
"@babel/cli": "^7.24.7",
|
|
58
51
|
"@babel/core": "^7.24.7",
|
|
59
52
|
"@babel/preset-env": "^7.24.7",
|
|
60
53
|
"@commitlint/cli": "^18.6.1",
|
|
61
54
|
"@commitlint/config-conventional": "^18.6.2",
|
|
62
|
-
"@
|
|
63
|
-
"
|
|
55
|
+
"@eslint/js": "^9.32.0",
|
|
56
|
+
"@eslint/markdown": "^7.1.0",
|
|
57
|
+
"@stylistic/eslint-plugin": "^5.2.2",
|
|
58
|
+
"babel-jest": "^30.0.0",
|
|
64
59
|
"cross-env": "^7.0.3",
|
|
65
60
|
"cspell": "^8.10.0",
|
|
66
61
|
"del": "^7.1.0",
|
|
67
62
|
"del-cli": "^5.1.0",
|
|
68
|
-
"eslint": "^
|
|
69
|
-
"eslint-config-prettier": "^
|
|
70
|
-
"eslint-
|
|
63
|
+
"eslint": "^9.32.0",
|
|
64
|
+
"eslint-config-prettier": "^10.1.8",
|
|
65
|
+
"eslint-config-webpack": "^4.5.1",
|
|
66
|
+
"eslint-plugin-import": "^2.32.0",
|
|
67
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
68
|
+
"eslint-plugin-n": "^17.21.1",
|
|
69
|
+
"eslint-plugin-prettier": "^5.5.3",
|
|
70
|
+
"eslint-plugin-unicorn": "^60.0.0",
|
|
71
|
+
"globals": "^16.3.0",
|
|
71
72
|
"husky": "^9.1.3",
|
|
72
|
-
"jest": "^
|
|
73
|
+
"jest": "^30.0.0",
|
|
73
74
|
"less": "^4.2.0",
|
|
74
75
|
"less-plugin-glob": "^3.0.0",
|
|
75
76
|
"lint-staged": "^15.2.7",
|
|
@@ -78,15 +79,23 @@
|
|
|
78
79
|
"prettier": "^3.3.2",
|
|
79
80
|
"standard-version": "^9.3.1",
|
|
80
81
|
"strip-ansi": "^7.1.0",
|
|
82
|
+
"typescript-eslint": "^8.38.0",
|
|
81
83
|
"webpack": "^5.92.1"
|
|
82
84
|
},
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
"peerDependencies": {
|
|
86
|
+
"@rspack/core": "0.x || ^1.0.0 || ^2.0.0-0",
|
|
87
|
+
"less": "^3.5.0 || ^4.0.0",
|
|
88
|
+
"webpack": "^5.0.0"
|
|
89
|
+
},
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"@rspack/core": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
94
|
+
"webpack": {
|
|
95
|
+
"optional": true
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"engines": {
|
|
99
|
+
"node": ">= 18.12.0"
|
|
100
|
+
}
|
|
92
101
|
}
|