less-loader 13.0.0 → 13.1.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 CHANGED
@@ -45,18 +45,27 @@ module.exports = {
45
45
  rules: [
46
46
  {
47
47
  test: /\.less$/i,
48
- use: [
49
- // compiles Less to CSS
50
- "style-loader",
51
- "css-loader",
52
- "less-loader",
53
- ],
48
+ // Uses the built-in CSS support of webpack, i.e. `.module.less` files
49
+ // are treated as CSS modules, other files are treated as plain CSS
50
+ type: "css/auto",
51
+ // Compiles Less to CSS
52
+ use: ["less-loader"],
54
53
  },
55
54
  ],
56
55
  },
56
+ experiments: {
57
+ // Enables the built-in CSS support of webpack
58
+ css: true,
59
+ },
57
60
  };
58
61
  ```
59
62
 
63
+ > [!NOTE]
64
+ >
65
+ > The built-in CSS support of webpack is the recommended way to handle the generated CSS, and needs webpack 5.87.0 or later. Since webpack 5.109.0 it is on by default (`experiments.css` defaults to `"auto"`), but `"auto"` switches it off when another `module.rules` entry handles `.css` files, so the examples below keep `experiments.css: true`. If such a rule still uses `css-loader`, give it `type: "javascript/auto"` so built-in CSS leaves those files to it.
66
+ > Its output is a `.css` file the page has to link: let webpack build the page — an [HTML entry or `output.html: true`](https://webpack.js.org/guides/native-html/) (webpack 5.108.0 or later; before 5.109.0 also set `experiments.html: true`) adds the `<link>` for you — set [`exportType: "style"`](https://webpack.js.org/guides/native-css/#output-modes-exporttype) (webpack 5.106.0 or later) to inject the styles from JavaScript instead, or link the emitted file yourself.
67
+ > Alternatively you can still chain the loader with the deprecated [`css-loader`](https://github.com/webpack/css-loader) and [`style-loader`](https://github.com/webpack/style-loader) (or the [`mini-css-extract-plugin`](https://github.com/webpack/mini-css-extract-plugin)), see [Using `css-loader` and `style-loader`](#using-css-loader-and-style-loader) — and the [Native CSS migration guide](https://webpack.js.org/guides/native-css/#migration-guide) to move off them.
68
+
60
69
  Finally, run `webpack` using the method you normally use (e.g., via CLI or an npm script).
61
70
 
62
71
  ## Options
@@ -96,13 +105,8 @@ module.exports = {
96
105
  rules: [
97
106
  {
98
107
  test: /\.less$/i,
108
+ type: "css/auto",
99
109
  use: [
100
- {
101
- loader: "style-loader",
102
- },
103
- {
104
- loader: "css-loader",
105
- },
106
110
  {
107
111
  loader: "less-loader",
108
112
  options: {
@@ -115,6 +119,9 @@ module.exports = {
115
119
  },
116
120
  ],
117
121
  },
122
+ experiments: {
123
+ css: true,
124
+ },
118
125
  };
119
126
  ```
120
127
 
@@ -128,9 +135,8 @@ module.exports = {
128
135
  rules: [
129
136
  {
130
137
  test: /\.less$/i,
138
+ type: "css/auto",
131
139
  use: [
132
- "style-loader",
133
- "css-loader",
134
140
  {
135
141
  loader: "less-loader",
136
142
  options: {
@@ -155,6 +161,9 @@ module.exports = {
155
161
  },
156
162
  ],
157
163
  },
164
+ experiments: {
165
+ css: true,
166
+ },
158
167
  };
159
168
  ```
160
169
 
@@ -185,9 +194,8 @@ module.exports = {
185
194
  rules: [
186
195
  {
187
196
  test: /\.less$/i,
197
+ type: "css/auto",
188
198
  use: [
189
- "style-loader",
190
- "css-loader",
191
199
  {
192
200
  loader: "less-loader",
193
201
  options: {
@@ -198,6 +206,9 @@ module.exports = {
198
206
  },
199
207
  ],
200
208
  },
209
+ experiments: {
210
+ css: true,
211
+ },
201
212
  };
202
213
  ```
203
214
 
@@ -211,9 +222,8 @@ module.exports = {
211
222
  rules: [
212
223
  {
213
224
  test: /\.less$/i,
225
+ type: "css/auto",
214
226
  use: [
215
- "style-loader",
216
- "css-loader",
217
227
  {
218
228
  loader: "less-loader",
219
229
  options: {
@@ -234,6 +244,9 @@ module.exports = {
234
244
  },
235
245
  ],
236
246
  },
247
+ experiments: {
248
+ css: true,
249
+ },
237
250
  };
238
251
  ```
239
252
 
@@ -245,9 +258,8 @@ module.exports = {
245
258
  rules: [
246
259
  {
247
260
  test: /\.less$/i,
261
+ type: "css/auto",
248
262
  use: [
249
- "style-loader",
250
- "css-loader",
251
263
  {
252
264
  loader: "less-loader",
253
265
  options: {
@@ -268,6 +280,9 @@ module.exports = {
268
280
  },
269
281
  ],
270
282
  },
283
+ experiments: {
284
+ css: true,
285
+ },
271
286
  };
272
287
  ```
273
288
 
@@ -292,14 +307,8 @@ module.exports = {
292
307
  rules: [
293
308
  {
294
309
  test: /\.less$/i,
310
+ type: "css/auto",
295
311
  use: [
296
- "style-loader",
297
- {
298
- loader: "css-loader",
299
- options: {
300
- sourceMap: true,
301
- },
302
- },
303
312
  {
304
313
  loader: "less-loader",
305
314
  options: {
@@ -310,6 +319,9 @@ module.exports = {
310
319
  },
311
320
  ],
312
321
  },
322
+ experiments: {
323
+ css: true,
324
+ },
313
325
  };
314
326
  ```
315
327
 
@@ -335,9 +347,8 @@ module.exports = {
335
347
  rules: [
336
348
  {
337
349
  test: /\.less$/i,
350
+ type: "css/auto",
338
351
  use: [
339
- "style-loader",
340
- "css-loader",
341
352
  {
342
353
  loader: "less-loader",
343
354
  options: {
@@ -348,6 +359,9 @@ module.exports = {
348
359
  },
349
360
  ],
350
361
  },
362
+ experiments: {
363
+ css: true,
364
+ },
351
365
  };
352
366
  ```
353
367
 
@@ -377,9 +391,8 @@ module.exports = {
377
391
  rules: [
378
392
  {
379
393
  test: /\.less$/i,
394
+ type: "css/auto",
380
395
  use: [
381
- "style-loader",
382
- "css-loader",
383
396
  {
384
397
  loader: "less-loader",
385
398
  options: {
@@ -390,6 +403,9 @@ module.exports = {
390
403
  },
391
404
  ],
392
405
  },
406
+ experiments: {
407
+ css: true,
408
+ },
393
409
  };
394
410
  ```
395
411
 
@@ -405,9 +421,8 @@ module.exports = {
405
421
  rules: [
406
422
  {
407
423
  test: /\.less$/i,
424
+ type: "css/auto",
408
425
  use: [
409
- "style-loader",
410
- "css-loader",
411
426
  {
412
427
  loader: "less-loader",
413
428
  options: {
@@ -418,6 +433,9 @@ module.exports = {
418
433
  },
419
434
  ],
420
435
  },
436
+ experiments: {
437
+ css: true,
438
+ },
421
439
  };
422
440
  ```
423
441
 
@@ -451,9 +469,8 @@ module.exports = {
451
469
  rules: [
452
470
  {
453
471
  test: /\.less$/i,
472
+ type: "css/auto",
454
473
  use: [
455
- "style-loader",
456
- "css-loader",
457
474
  {
458
475
  loader: "less-loader",
459
476
  options: {
@@ -464,6 +481,9 @@ module.exports = {
464
481
  },
465
482
  ],
466
483
  },
484
+ experiments: {
485
+ css: true,
486
+ },
467
487
  };
468
488
  ```
469
489
 
@@ -471,7 +491,35 @@ module.exports = {
471
491
 
472
492
  ### Normal usage
473
493
 
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.
494
+ Set the module `type` to `css/auto` and enable `experiments.css` to let webpack handle the generated CSS with its built-in CSS support, without any extra loaders or plugins.
495
+
496
+ **webpack.config.js**
497
+
498
+ ```js
499
+ module.exports = {
500
+ module: {
501
+ rules: [
502
+ {
503
+ test: /\.less$/i,
504
+ type: "css/auto", // Handles the generated CSS using the built-in CSS support of webpack
505
+ use: ["less-loader"], // Compiles Less to CSS
506
+ },
507
+ ],
508
+ },
509
+ experiments: {
510
+ css: true,
511
+ },
512
+ };
513
+ ```
514
+
515
+ The `css/auto` module type treats `*.module.less` files as [CSS modules](#css-modules) and any other file as plain CSS.
516
+ Use `type: "css"` to always treat the file as plain CSS, or `type: "css/module"` to always treat it as a CSS module.
517
+
518
+ Unfortunately, Less doesn't map all options 1-by-1 to camelCase. When in doubt, [check their executable](https://github.com/less/less.js/blob/3.x/bin/lessc) and search for the dash-case option.
519
+
520
+ ### Using `css-loader` and `style-loader`
521
+
522
+ The built-in CSS support of webpack is not mandatory: on setups that still need them, you can chain the `less-loader` with the deprecated [`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. New projects should use the built-in CSS support instead — see the [Native CSS migration guide](https://webpack.js.org/guides/native-css/#migration-guide).
475
523
 
476
524
  **webpack.config.js**
477
525
 
@@ -498,7 +546,7 @@ module.exports = {
498
546
  };
499
547
  ```
500
548
 
501
- Unfortunately, Less doesn't map all options 1-by-1 to camelCase. When in doubt, [check their executable](https://github.com/less/less.js/blob/3.x/bin/lessc) and search for the dash-case option.
549
+ Note that in this case the `type` and `experiments.css` options should not be set for this rule, and options like `sourceMap` have to be enabled for the `css-loader` too.
502
550
 
503
551
  ### Source maps
504
552
 
@@ -513,14 +561,8 @@ module.exports = {
513
561
  rules: [
514
562
  {
515
563
  test: /\.less$/i,
564
+ type: "css/auto",
516
565
  use: [
517
- "style-loader",
518
- {
519
- loader: "css-loader",
520
- options: {
521
- sourceMap: true,
522
- },
523
- },
524
566
  {
525
567
  loader: "less-loader",
526
568
  options: {
@@ -531,6 +573,9 @@ module.exports = {
531
573
  },
532
574
  ],
533
575
  },
576
+ experiments: {
577
+ css: true,
578
+ },
534
579
  };
535
580
  ```
536
581
 
@@ -538,7 +583,10 @@ If you want to edit the original Less files inside Chrome, [there's a good blog
538
583
 
539
584
  ### In production
540
585
 
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.
586
+ The built-in CSS support of webpack always extracts style sheets into dedicated files, so your styles are not dependent on JavaScript, which improves performance and cacheability.
587
+ The name of the generated files can be configured using the [`output.cssFilename`](https://webpack.js.org/configuration/output/#outputcssfilename) and [`output.cssChunkFilename`](https://webpack.js.org/configuration/output/#outputcsschunkfilename) options.
588
+
589
+ When you chain the loader with `css-loader` and `style-loader` instead, extract the style sheets into a dedicated file in production using the deprecated [MiniCssExtractPlugin](https://github.com/webpack/mini-css-extract-plugin).
542
590
 
543
591
  ### Imports
544
592
 
@@ -568,10 +616,14 @@ module.exports = {
568
616
  rules: [
569
617
  {
570
618
  test: /\.less$/i,
571
- use: ["style-loader", "css-loader", "less-loader"],
619
+ type: "css/auto",
620
+ use: ["less-loader"],
572
621
  },
573
622
  ],
574
623
  },
624
+ experiments: {
625
+ css: true,
626
+ },
575
627
  resolve: {
576
628
  byDependency: {
577
629
  // More options can be found here https://webpack.js.org/configuration/resolve/
@@ -595,13 +647,8 @@ module.exports = {
595
647
  rules: [
596
648
  {
597
649
  test: /\.less$/i,
650
+ type: "css/auto",
598
651
  use: [
599
- {
600
- loader: "style-loader",
601
- },
602
- {
603
- loader: "css-loader",
604
- },
605
652
  {
606
653
  loader: "less-loader",
607
654
  options: {
@@ -614,6 +661,9 @@ module.exports = {
614
661
  },
615
662
  ],
616
663
  },
664
+ experiments: {
665
+ css: true,
666
+ },
617
667
  };
618
668
  ```
619
669
 
@@ -668,14 +718,41 @@ Bundling CSS with webpack has some nice advantages like referencing images and f
668
718
 
669
719
  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.
670
720
 
671
- There are two possibilities to extract a style sheet from the bundle:
721
+ The built-in CSS support of webpack does this out of the box: every entry point and chunk gets its own style sheet, no extra plugin required.
722
+ When you chain the loader with the `css-loader` instead, use the deprecated [`MiniCssExtractPlugin`](https://github.com/webpack/mini-css-extract-plugin) to extract a style sheet from the bundle.
723
+
724
+ ### CSS modules
672
725
 
673
- - [`extract-loader`](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
674
- - [`MiniCssExtractPlugin`](https://github.com/webpack/mini-css-extract-plugin) (more complex, but works in all use-cases)
726
+ With the built-in CSS support of webpack, `*.module.less` files are treated as [CSS modules](https://github.com/css-modules/css-modules) when the module `type` is `css/auto`, and all files are treated as CSS modules when the module `type` is `css/module`:
675
727
 
676
- ### CSS modules gotcha
728
+ **webpack.config.js**
729
+
730
+ ```js
731
+ module.exports = {
732
+ module: {
733
+ rules: [
734
+ {
735
+ test: /\.less$/i,
736
+ type: "css/auto",
737
+ use: ["less-loader"],
738
+ },
739
+ ],
740
+ },
741
+ experiments: {
742
+ css: true,
743
+ },
744
+ };
745
+ ```
746
+
747
+ **index.js**
748
+
749
+ ```js
750
+ import * as styles from "./style.module.less";
751
+
752
+ document.body.className = styles.box;
753
+ ```
677
754
 
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.
755
+ There is a known problem when using Less with CSS modules regarding relative file paths in `url(...)` statements.
679
756
  [See this issue for an explanation](https://github.com/webpack/less-loader/issues/109#issuecomment-253797335).
680
757
 
681
758
  ## Contributing
package/dist/cjs/index.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _nodePath = _interopRequireDefault(require("node:path"));
8
+ var _optionsCheck = _interopRequireDefault(require("./options.check.js"));
8
9
  var _options = _interopRequireDefault(require("./options.json"));
9
10
  var _utils = require("./utils.js");
10
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -21,7 +22,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
21
22
  * @returns {Promise<void>} loader result
22
23
  */
23
24
  async function lessLoader(content) {
24
- const options = this.getOptions(/** @type {Schema} */_options.default);
25
+ const options = this.getOptions(/** @type {Schema} */_options.default, _optionsCheck.default);
25
26
  const callback = this.async();
26
27
  let implementation;
27
28
  try {
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.validate = exports.default = void 0;
7
+ /* eslint-disable */
8
+ // @ts-nocheck
9
+ /*
10
+ * This file was automatically generated by "schema-utils".
11
+ * DO NOT MODIFY BY HAND.
12
+ */
13
+ const validate = exports.validate = e;
14
+ var _default = exports.default = e;
15
+ let r = {
16
+ type: "object",
17
+ properties: {
18
+ lessOptions: {
19
+ anyOf: [{
20
+ type: "object",
21
+ additionalProperties: !0
22
+ }, {
23
+ instanceof: "Function"
24
+ }]
25
+ },
26
+ additionalData: {
27
+ anyOf: [{
28
+ type: "string"
29
+ }, {
30
+ instanceof: "Function"
31
+ }]
32
+ },
33
+ sourceMap: {
34
+ type: "boolean"
35
+ },
36
+ webpackImporter: {
37
+ anyOf: [{
38
+ type: "boolean"
39
+ }, {
40
+ type: "string",
41
+ enum: ["only"]
42
+ }]
43
+ },
44
+ implementation: {
45
+ anyOf: [{
46
+ type: "string"
47
+ }, {
48
+ type: "object"
49
+ }]
50
+ },
51
+ lessLogAsWarnOrErr: {
52
+ type: "boolean"
53
+ }
54
+ },
55
+ additionalProperties: !1,
56
+ $id: "options.json"
57
+ };
58
+ function e(s, {
59
+ instancePath = "",
60
+ parentData,
61
+ parentDataProperty,
62
+ rootData = s
63
+ } = {}) {
64
+ let a = null,
65
+ o = 0;
66
+ if (o === 0) if (s && "object" == typeof s && !Array.isArray(s)) {
67
+ let d = o;
68
+ for (let r in s) if (!(r === "lessOptions" || r === "additionalData" || r === "sourceMap" || r === "webpackImporter" || r === "implementation" || r === "lessLogAsWarnOrErr")) return e.errors = [{
69
+ params: {
70
+ additionalProperty: r
71
+ }
72
+ }], !1;
73
+ if (d === o) {
74
+ if (s.lessOptions !== void 0) {
75
+ let r = s.lessOptions,
76
+ i = o,
77
+ n = o,
78
+ v = !1,
79
+ d = o;
80
+ if (o === d) if (!(r && "object" == typeof r && !Array.isArray(r))) {
81
+ let r = {
82
+ params: {
83
+ type: "object"
84
+ }
85
+ };
86
+ a === null ? a = [r] : a.push(r), o++;
87
+ }
88
+ var t = d === o;
89
+ if (!(v = v || t)) {
90
+ let e = o;
91
+ if (!(r instanceof Function)) {
92
+ let r = {
93
+ params: {}
94
+ };
95
+ a === null ? a = [r] : a.push(r), o++;
96
+ }
97
+ var t = e === o;
98
+ v = v || t;
99
+ }
100
+ if (!v) {
101
+ let r = {
102
+ params: {}
103
+ };
104
+ a === null ? a = [r] : a.push(r), o++, e.errors = a;
105
+ return !1;
106
+ }
107
+ o = n;
108
+ if (a !== null) n ? a.length = n : a = null;
109
+ var l = i === o;
110
+ } else var l = !0;
111
+ if (l) {
112
+ if (s.additionalData !== void 0) {
113
+ let r = s.additionalData,
114
+ t = o,
115
+ n = o,
116
+ v = !1,
117
+ d = o;
118
+ if ("string" != typeof r) {
119
+ let r = {
120
+ params: {
121
+ type: "string"
122
+ }
123
+ };
124
+ a === null ? a = [r] : a.push(r), o++;
125
+ }
126
+ var i = d === o;
127
+ if (!(v = v || i)) {
128
+ let e = o;
129
+ if (!(r instanceof Function)) {
130
+ let r = {
131
+ params: {}
132
+ };
133
+ a === null ? a = [r] : a.push(r), o++;
134
+ }
135
+ var i = e === o;
136
+ v = v || i;
137
+ }
138
+ if (!v) {
139
+ let r = {
140
+ params: {}
141
+ };
142
+ a === null ? a = [r] : a.push(r), o++, e.errors = a;
143
+ return !1;
144
+ }
145
+ o = n;
146
+ if (a !== null) n ? a.length = n : a = null;
147
+ var l = t === o;
148
+ } else var l = !0;
149
+ if (l) {
150
+ if (s.sourceMap !== void 0) {
151
+ let r = o;
152
+ if ("boolean" != typeof s.sourceMap) return e.errors = [{
153
+ params: {
154
+ type: "boolean"
155
+ }
156
+ }], !1;
157
+ var l = r === o;
158
+ } else var l = !0;
159
+ if (l) {
160
+ if (s.webpackImporter !== void 0) {
161
+ let t = s.webpackImporter,
162
+ i = o,
163
+ v = o,
164
+ d = !1,
165
+ f = o;
166
+ if ("boolean" != typeof t) {
167
+ let r = {
168
+ params: {
169
+ type: "boolean"
170
+ }
171
+ };
172
+ a === null ? a = [r] : a.push(r), o++;
173
+ }
174
+ var n = f === o;
175
+ if (!(d = d || n)) {
176
+ let e = o;
177
+ if ("string" != typeof t) {
178
+ let r = {
179
+ params: {
180
+ type: "string"
181
+ }
182
+ };
183
+ a === null ? a = [r] : a.push(r), o++;
184
+ }
185
+ if (t !== "only") {
186
+ let e = {
187
+ params: {
188
+ allowedValues: r.properties.webpackImporter.anyOf[1].enum
189
+ }
190
+ };
191
+ a === null ? a = [e] : a.push(e), o++;
192
+ }
193
+ var n = e === o;
194
+ d = d || n;
195
+ }
196
+ if (!d) {
197
+ let r = {
198
+ params: {}
199
+ };
200
+ a === null ? a = [r] : a.push(r), o++, e.errors = a;
201
+ return !1;
202
+ }
203
+ o = v;
204
+ if (a !== null) v ? a.length = v : a = null;
205
+ var l = i === o;
206
+ } else var l = !0;
207
+ if (l) {
208
+ if (s.implementation !== void 0) {
209
+ let r = s.implementation,
210
+ t = o,
211
+ i = o,
212
+ n = !1,
213
+ d = o;
214
+ if ("string" != typeof r) {
215
+ let r = {
216
+ params: {
217
+ type: "string"
218
+ }
219
+ };
220
+ a === null ? a = [r] : a.push(r), o++;
221
+ }
222
+ var v = d === o;
223
+ if (!(n = n || v)) {
224
+ let e = o;
225
+ if (!(r && "object" == typeof r && !Array.isArray(r))) {
226
+ let r = {
227
+ params: {
228
+ type: "object"
229
+ }
230
+ };
231
+ a === null ? a = [r] : a.push(r), o++;
232
+ }
233
+ var v = e === o;
234
+ n = n || v;
235
+ }
236
+ if (!n) {
237
+ let r = {
238
+ params: {}
239
+ };
240
+ a === null ? a = [r] : a.push(r), o++, e.errors = a;
241
+ return !1;
242
+ }
243
+ o = i;
244
+ if (a !== null) i ? a.length = i : a = null;
245
+ var l = t === o;
246
+ } else var l = !0;
247
+ if (l) if (s.lessLogAsWarnOrErr !== void 0) {
248
+ let r = o;
249
+ if ("boolean" != typeof s.lessLogAsWarnOrErr) return e.errors = [{
250
+ params: {
251
+ type: "boolean"
252
+ }
253
+ }], !1;
254
+ var l = r === o;
255
+ } else var l = !0;
256
+ }
257
+ }
258
+ }
259
+ }
260
+ }
261
+ } else return e.errors = [{
262
+ params: {
263
+ type: "object"
264
+ }
265
+ }], !1;
266
+ return e.errors = a, o === 0;
267
+ }
package/dist/cjs/utils.js CHANGED
@@ -253,8 +253,9 @@ function getLessOptions(loaderContext, loaderOptions, implementation) {
253
253
  const lessOptions = {
254
254
  // @ts-expect-error bad types
255
255
  relativeUrls: true,
256
- // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
257
- filename: loaderContext.resourcePath,
256
+ // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry;
257
+ // a `data:` resource has no path of its own, so it reads as a file in the loader's context
258
+ filename: loaderContext.resourcePath.startsWith("data:") ? _nodePath.default.join(loaderContext.context, "stdin.less") : loaderContext.resourcePath,
258
259
  ...options
259
260
  };
260
261
 
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "node:path";
2
+ import check from "./options.check.js";
2
3
  import schema from "./options.json" with { type: "json" };
3
4
  import { errorFactory, getLessImplementation, getLessOptions, isUnsupportedUrl, normalizeSourceMap } from "./utils.js";
4
5
 
@@ -15,7 +16,7 @@ import { errorFactory, getLessImplementation, getLessOptions, isUnsupportedUrl,
15
16
  * @returns {Promise<void>} loader result
16
17
  */
17
18
  async function lessLoader(content) {
18
- const options = this.getOptions(/** @type {Schema} */schema);
19
+ const options = this.getOptions(/** @type {Schema} */schema, check);
19
20
  const callback = this.async();
20
21
  let implementation;
21
22
  try {
@@ -0,0 +1,261 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ /*
4
+ * This file was automatically generated by "schema-utils".
5
+ * DO NOT MODIFY BY HAND.
6
+ */
7
+ export const validate = e;
8
+ export default e;
9
+ let r = {
10
+ type: "object",
11
+ properties: {
12
+ lessOptions: {
13
+ anyOf: [{
14
+ type: "object",
15
+ additionalProperties: !0
16
+ }, {
17
+ instanceof: "Function"
18
+ }]
19
+ },
20
+ additionalData: {
21
+ anyOf: [{
22
+ type: "string"
23
+ }, {
24
+ instanceof: "Function"
25
+ }]
26
+ },
27
+ sourceMap: {
28
+ type: "boolean"
29
+ },
30
+ webpackImporter: {
31
+ anyOf: [{
32
+ type: "boolean"
33
+ }, {
34
+ type: "string",
35
+ enum: ["only"]
36
+ }]
37
+ },
38
+ implementation: {
39
+ anyOf: [{
40
+ type: "string"
41
+ }, {
42
+ type: "object"
43
+ }]
44
+ },
45
+ lessLogAsWarnOrErr: {
46
+ type: "boolean"
47
+ }
48
+ },
49
+ additionalProperties: !1,
50
+ $id: "options.json"
51
+ };
52
+ function e(s, {
53
+ instancePath = "",
54
+ parentData,
55
+ parentDataProperty,
56
+ rootData = s
57
+ } = {}) {
58
+ let a = null,
59
+ o = 0;
60
+ if (o === 0) if (s && "object" == typeof s && !Array.isArray(s)) {
61
+ let d = o;
62
+ for (let r in s) if (!(r === "lessOptions" || r === "additionalData" || r === "sourceMap" || r === "webpackImporter" || r === "implementation" || r === "lessLogAsWarnOrErr")) return e.errors = [{
63
+ params: {
64
+ additionalProperty: r
65
+ }
66
+ }], !1;
67
+ if (d === o) {
68
+ if (s.lessOptions !== void 0) {
69
+ let r = s.lessOptions,
70
+ i = o,
71
+ n = o,
72
+ v = !1,
73
+ d = o;
74
+ if (o === d) if (!(r && "object" == typeof r && !Array.isArray(r))) {
75
+ let r = {
76
+ params: {
77
+ type: "object"
78
+ }
79
+ };
80
+ a === null ? a = [r] : a.push(r), o++;
81
+ }
82
+ var t = d === o;
83
+ if (!(v = v || t)) {
84
+ let e = o;
85
+ if (!(r instanceof Function)) {
86
+ let r = {
87
+ params: {}
88
+ };
89
+ a === null ? a = [r] : a.push(r), o++;
90
+ }
91
+ var t = e === o;
92
+ v = v || t;
93
+ }
94
+ if (!v) {
95
+ let r = {
96
+ params: {}
97
+ };
98
+ a === null ? a = [r] : a.push(r), o++, e.errors = a;
99
+ return !1;
100
+ }
101
+ o = n;
102
+ if (a !== null) n ? a.length = n : a = null;
103
+ var l = i === o;
104
+ } else var l = !0;
105
+ if (l) {
106
+ if (s.additionalData !== void 0) {
107
+ let r = s.additionalData,
108
+ t = o,
109
+ n = o,
110
+ v = !1,
111
+ d = o;
112
+ if ("string" != typeof r) {
113
+ let r = {
114
+ params: {
115
+ type: "string"
116
+ }
117
+ };
118
+ a === null ? a = [r] : a.push(r), o++;
119
+ }
120
+ var i = d === o;
121
+ if (!(v = v || i)) {
122
+ let e = o;
123
+ if (!(r instanceof Function)) {
124
+ let r = {
125
+ params: {}
126
+ };
127
+ a === null ? a = [r] : a.push(r), o++;
128
+ }
129
+ var i = e === o;
130
+ v = v || i;
131
+ }
132
+ if (!v) {
133
+ let r = {
134
+ params: {}
135
+ };
136
+ a === null ? a = [r] : a.push(r), o++, e.errors = a;
137
+ return !1;
138
+ }
139
+ o = n;
140
+ if (a !== null) n ? a.length = n : a = null;
141
+ var l = t === o;
142
+ } else var l = !0;
143
+ if (l) {
144
+ if (s.sourceMap !== void 0) {
145
+ let r = o;
146
+ if ("boolean" != typeof s.sourceMap) return e.errors = [{
147
+ params: {
148
+ type: "boolean"
149
+ }
150
+ }], !1;
151
+ var l = r === o;
152
+ } else var l = !0;
153
+ if (l) {
154
+ if (s.webpackImporter !== void 0) {
155
+ let t = s.webpackImporter,
156
+ i = o,
157
+ v = o,
158
+ d = !1,
159
+ f = o;
160
+ if ("boolean" != typeof t) {
161
+ let r = {
162
+ params: {
163
+ type: "boolean"
164
+ }
165
+ };
166
+ a === null ? a = [r] : a.push(r), o++;
167
+ }
168
+ var n = f === o;
169
+ if (!(d = d || n)) {
170
+ let e = o;
171
+ if ("string" != typeof t) {
172
+ let r = {
173
+ params: {
174
+ type: "string"
175
+ }
176
+ };
177
+ a === null ? a = [r] : a.push(r), o++;
178
+ }
179
+ if (t !== "only") {
180
+ let e = {
181
+ params: {
182
+ allowedValues: r.properties.webpackImporter.anyOf[1].enum
183
+ }
184
+ };
185
+ a === null ? a = [e] : a.push(e), o++;
186
+ }
187
+ var n = e === o;
188
+ d = d || n;
189
+ }
190
+ if (!d) {
191
+ let r = {
192
+ params: {}
193
+ };
194
+ a === null ? a = [r] : a.push(r), o++, e.errors = a;
195
+ return !1;
196
+ }
197
+ o = v;
198
+ if (a !== null) v ? a.length = v : a = null;
199
+ var l = i === o;
200
+ } else var l = !0;
201
+ if (l) {
202
+ if (s.implementation !== void 0) {
203
+ let r = s.implementation,
204
+ t = o,
205
+ i = o,
206
+ n = !1,
207
+ d = o;
208
+ if ("string" != typeof r) {
209
+ let r = {
210
+ params: {
211
+ type: "string"
212
+ }
213
+ };
214
+ a === null ? a = [r] : a.push(r), o++;
215
+ }
216
+ var v = d === o;
217
+ if (!(n = n || v)) {
218
+ let e = o;
219
+ if (!(r && "object" == typeof r && !Array.isArray(r))) {
220
+ let r = {
221
+ params: {
222
+ type: "object"
223
+ }
224
+ };
225
+ a === null ? a = [r] : a.push(r), o++;
226
+ }
227
+ var v = e === o;
228
+ n = n || v;
229
+ }
230
+ if (!n) {
231
+ let r = {
232
+ params: {}
233
+ };
234
+ a === null ? a = [r] : a.push(r), o++, e.errors = a;
235
+ return !1;
236
+ }
237
+ o = i;
238
+ if (a !== null) i ? a.length = i : a = null;
239
+ var l = t === o;
240
+ } else var l = !0;
241
+ if (l) if (s.lessLogAsWarnOrErr !== void 0) {
242
+ let r = o;
243
+ if ("boolean" != typeof s.lessLogAsWarnOrErr) return e.errors = [{
244
+ params: {
245
+ type: "boolean"
246
+ }
247
+ }], !1;
248
+ var l = r === o;
249
+ } else var l = !0;
250
+ }
251
+ }
252
+ }
253
+ }
254
+ }
255
+ } else return e.errors = [{
256
+ params: {
257
+ type: "object"
258
+ }
259
+ }], !1;
260
+ return e.errors = a, o === 0;
261
+ }
package/dist/esm/utils.js CHANGED
@@ -243,8 +243,9 @@ function getLessOptions(loaderContext, loaderOptions, implementation) {
243
243
  const lessOptions = {
244
244
  // @ts-expect-error bad types
245
245
  relativeUrls: true,
246
- // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
247
- filename: loaderContext.resourcePath,
246
+ // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry;
247
+ // a `data:` resource has no path of its own, so it reads as a file in the loader's context
248
+ filename: loaderContext.resourcePath.startsWith("data:") ? path.join(loaderContext.context, "stdin.less") : loaderContext.resourcePath,
248
249
  ...options
249
250
  };
250
251
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "less-loader",
3
- "version": "13.0.0",
3
+ "version": "13.1.1",
4
4
  "description": "A Less loader for webpack. Compiles Less to CSS.",
5
5
  "keywords": [
6
6
  "webpack",
@@ -50,14 +50,16 @@
50
50
  "lint:code": "eslint --cache .",
51
51
  "lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"",
52
52
  "lint:types": "tsc --pretty --noEmit",
53
+ "lint:schema": "schema-utils precompile --check --minify src/options.json",
53
54
  "fmt": "npm run fmt:check -- --write",
54
55
  "fmt:check": "prettier --list-different --cache --ignore-unknown .",
55
- "fix": "npm run fix:code && npm run fmt",
56
+ "fix": "npm run fix:schema && npm run fix:code && npm run fmt",
56
57
  "fix:code": "npm run lint:code -- --fix",
58
+ "fix:schema": "schema-utils precompile --minify src/options.json",
57
59
  "pretest": "npm run lint",
58
60
  "test": "npm run test:base",
59
61
  "test:base": "node --import ./test/setup-snapshots.js --test --test-force-exit --test-reporter=dot --test-reporter-destination=stdout --experimental-test-module-mocks",
60
- "test:coverage": "npm run test:base -- --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage.lcov --test-coverage-include=\"src/**/*.js\"",
62
+ "test:coverage": "npm run test:base -- --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage.lcov --test-coverage-include=\"src/**/*.js\" --test-coverage-exclude=\"src/options.check.js\"",
61
63
  "prepare": "husky && npm run build",
62
64
  "version": "changeset version",
63
65
  "release": "npm run build && changeset publish"
@@ -67,7 +69,7 @@
67
69
  },
68
70
  "devDependencies": {
69
71
  "@babel/cli": "^7.24.7",
70
- "@babel/core": "^7.24.7",
72
+ "@babel/core": "^7.29.6",
71
73
  "@babel/preset-env": "^7.29.5",
72
74
  "@changesets/cli": "^2.30.0",
73
75
  "@changesets/get-github-info": "^0.8.0",
@@ -78,14 +80,15 @@
78
80
  "eslint": "^9.32.0",
79
81
  "eslint-config-webpack": "^4.9.6",
80
82
  "husky": "^9.1.3",
81
- "less": "^4.6.4",
83
+ "less": "^4.6.5",
82
84
  "less-plugin-glob": "^3.0.0",
83
85
  "lint-staged": "^17.0.5",
84
86
  "memfs": "^4.57.2",
85
87
  "npm-run-all": "^4.1.5",
86
88
  "prettier": "^3.8.3",
89
+ "schema-utils": "^4.8.5",
87
90
  "typescript": "^6.0.3",
88
- "webpack": "^5.107.0"
91
+ "webpack": "^5.113.0"
89
92
  },
90
93
  "peerDependencies": {
91
94
  "@rspack/core": "0.x || ^1.0.0 || ^2.0.0-0",
@@ -0,0 +1,25 @@
1
+ export function validate(
2
+ s: any,
3
+ {
4
+ instancePath,
5
+ parentData,
6
+ parentDataProperty,
7
+ rootData,
8
+ }?: {
9
+ instancePath?: string | undefined;
10
+ rootData?: any;
11
+ },
12
+ ): any;
13
+ export default e;
14
+ declare function e(
15
+ s: any,
16
+ {
17
+ instancePath,
18
+ parentData,
19
+ parentDataProperty,
20
+ rootData,
21
+ }?: {
22
+ instancePath?: string | undefined;
23
+ rootData?: any;
24
+ },
25
+ ): any;