less-loader 12.2.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 CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  # less-loader
15
15
 
16
- A Less loader for webpack. Compiles Less to CSS.
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` config. For example:
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
- And run `webpack` via your preferred method.
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/#rule-options-rule-query). See the [Less documentation](http://lesscss.org/usage/#command-line-usage-options) for all available options in dash-case. Since we're passing these options to Less programmatically, you need to pass them in camelCase here:
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 through to Less.
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 passed through to Less based off of the loader context.
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/Appends `Less` code to the actual entry file.
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 "@value: 100px;" + content;
226
+ return `@value: 100px;${content}`;
223
227
  }
224
228
 
225
- return "@value: 200px;" + content;
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 "@value: 100px;" + content;
260
+ return `@value: 100px;${content}`;
257
261
  }
258
262
 
259
- return "@value: 200px;" + content;
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. All values enable source map generation except `eval` and `false` value.
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
 
@@ -313,12 +318,12 @@ module.exports = {
313
318
  Type:
314
319
 
315
320
  ```ts
316
- type webpackImporter = boolean;
321
+ type webpackImporter = boolean | "only";
317
322
  ```
318
323
 
319
324
  Default: `true`
320
325
 
321
- Enables/Disables the default `webpack` importer.
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, not just logs.
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 the [`css-loader`](https://github.com/webpack-contrib/css-loader) and the [`style-loader`](https://github.com/webpack-contrib/style-loader) to immediately apply all styles to the DOM.
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", // creates style nodes from JS strings
486
+ loader: "style-loader", // Creates style nodes from JS strings
478
487
  },
479
488
  {
480
- loader: "css-loader", // translates CSS into CommonJS
489
+ loader: "css-loader", // Translates CSS into CommonJS
481
490
  },
482
491
  {
483
- loader: "less-loader", // compiles Less to CSS
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-contrib/mini-css-extract-plugin). This way your styles are not dependent on JavaScript.
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
 
@@ -633,40 +644,46 @@ module.exports = {
633
644
  };
634
645
  ```
635
646
 
636
- > **Note**
647
+ > [!NOTE]
637
648
  >
638
- > Access to the [loader context](https://webpack.js.org/api/loaders/#the-loader-context) inside the custom plugin can be done using the `pluginManager.webpackLoaderContext` property.
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: function (less, pluginManager, functions) {
643
- functions.add("pi", function () {
644
- // Loader context is available in `pluginManager.webpackLoaderContext`
645
-
646
- return Math.PI;
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 [hot module replacement](https://webpack.js.org/concepts/hot-module-replacement/) in development. 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.
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-contrib/mini-css-extract-plugin) (more complex, but works in all use-cases)
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 with Less and [CSS modules](https://github.com/css-modules/css-modules) regarding relative file paths in `url(...)` statements. [See this issue for an explanation](https://github.com/webpack-contrib/less-loader/issues/109#issuecomment-253797335).
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
- Please take a moment to read our contributing guidelines if you haven't yet done so.
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](./.github/CONTRIBUTING.md)
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-contrib/less-loader/workflows/less-loader/badge.svg
680
- [tests-url]: https://github.com/webpack-contrib/less-loader/actions
681
- [cover]: https://codecov.io/gh/webpack-contrib/less-loader/branch/master/graph/badge.svg
682
- [cover-url]: https://codecov.io/gh/webpack-contrib/less-loader
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,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _path = _interopRequireDefault(require("path"));
7
+ var _nodePath = _interopRequireDefault(require("node:path"));
8
8
  var _options = _interopRequireDefault(require("./options.json"));
9
9
  var _utils = require("./utils");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  async function lessLoader(source) {
12
12
  const options = this.getOptions(_options.default);
13
13
  const callback = this.async();
@@ -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-contrib/less-loader/issues/357
70
- this.addDependency(_path.default.normalize(error.filename));
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
- imports.forEach(item => {
84
+ for (const item of imports) {
85
85
  if ((0, _utils.isUnsupportedUrl)(item)) {
86
- return;
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-contrib/less-loader/issues/357
91
- const normalizedItem = _path.default.normalize(item);
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 (_path.default.isAbsolute(normalizedItem)) {
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-contrib/less-loader#lessoptions",
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-contrib/less-loader#additionalData",
20
+ "link": "https://github.com/webpack/less-loader#additionalData",
21
21
  "anyOf": [
22
22
  {
23
23
  "type": "string"
@@ -29,17 +29,25 @@
29
29
  },
30
30
  "sourceMap": {
31
31
  "description": "Enables/Disables generation of source maps.",
32
- "link": "https://github.com/webpack-contrib/less-loader#sourcemap",
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-contrib/less-loader#webpackimporter",
38
- "type": "boolean"
37
+ "link": "https://github.com/webpack/less-loader#webpackimporter",
38
+ "anyOf": [
39
+ {
40
+ "type": "boolean"
41
+ },
42
+ {
43
+ "type": "string",
44
+ "enum": ["only"]
45
+ }
46
+ ]
39
47
  },
40
48
  "implementation": {
41
49
  "description": "The implementation of the `Less` to be used.",
42
- "link": "https://github.com/webpack-contrib/less-loader#implementation",
50
+ "link": "https://github.com/webpack/less-loader#implementation",
43
51
  "anyOf": [
44
52
  {
45
53
  "type": "string"
@@ -51,7 +59,7 @@
51
59
  },
52
60
  "lessLogAsWarnOrErr": {
53
61
  "description": "Less warnings and errors will be webpack warnings or errors.",
54
- "link": "https://github.com/webpack-contrib/less-loader#lesslogaswarnorerr",
62
+ "link": "https://github.com/webpack/less-loader#lesslogaswarnorerr",
55
63
  "type": "boolean"
56
64
  }
57
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 _path = _interopRequireDefault(require("path"));
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- /* eslint-disable class-methods-use-this */
11
+ var _nodePath = _interopRequireDefault(require("node:path"));
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
13
  const trailingSlash = /[/\\]$/;
15
14
 
16
15
  // This somewhat changed in Less 3.x. Now the file name comes without the
@@ -39,6 +38,7 @@ const MODULE_REQUEST_REGEX = /^[^?]*~/;
39
38
  * @returns {LessPlugin}
40
39
  */
41
40
  function createWebpackLessPlugin(loaderContext, implementation) {
41
+ const lessOptions = loaderContext.getOptions();
42
42
  const resolve = loaderContext.getResolve({
43
43
  dependencyType: "less",
44
44
  conditionNames: ["less", "style", "..."],
@@ -82,7 +82,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
82
82
  }
83
83
  async resolveRequests(context, possibleRequests) {
84
84
  if (possibleRequests.length === 0) {
85
- return Promise.reject();
85
+ throw new Error("No possible requests to resolve");
86
86
  }
87
87
  let result;
88
88
  try {
@@ -99,27 +99,27 @@ function createWebpackLessPlugin(loaderContext, implementation) {
99
99
  async loadFile(filename, ...args) {
100
100
  let result;
101
101
  try {
102
- if (IS_SPECIAL_MODULE_IMPORT.test(filename)) {
103
- const error = new Error();
102
+ if (IS_SPECIAL_MODULE_IMPORT.test(filename) || lessOptions.webpackImporter === "only") {
103
+ const error = new Error("Next");
104
104
  error.type = "Next";
105
105
  throw error;
106
106
  }
107
107
  result = await super.loadFile(filename, ...args);
108
108
  } catch (error) {
109
109
  if (error.type !== "File" && error.type !== "Next") {
110
- return Promise.reject(error);
110
+ throw error;
111
111
  }
112
112
  try {
113
113
  result = await this.resolveFilename(filename, ...args);
114
- } catch (webpackResolveError) {
115
- error.message = `Less resolver error:\n${error.message}\n\n` + `Webpack resolver error details:\n${webpackResolveError.details}\n\n` + `Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`;
116
- return Promise.reject(error);
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;
117
117
  }
118
118
  loaderContext.addDependency(result);
119
119
  return super.loadFile(result, ...args);
120
120
  }
121
- const absoluteFilename = _path.default.isAbsolute(result.filename) ? result.filename : _path.default.resolve(".", result.filename);
122
- loaderContext.addDependency(_path.default.normalize(absoluteFilename));
121
+ const absoluteFilename = _nodePath.default.isAbsolute(result.filename) ? result.filename : _nodePath.default.resolve(".", result.filename);
122
+ loaderContext.addDependency(_nodePath.default.normalize(absoluteFilename));
123
123
  return result;
124
124
  }
125
125
  }
@@ -148,14 +148,13 @@ function getLessOptions(loaderContext, loaderOptions, implementation) {
148
148
  filename: loaderContext.resourcePath,
149
149
  ...options
150
150
  };
151
- const plugins = lessOptions.plugins.slice();
152
- const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" ? loaderOptions.webpackImporter : true;
151
+ const plugins = [...lessOptions.plugins];
152
+ const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" || loaderOptions.webpackImporter === "only" ? loaderOptions.webpackImporter : true;
153
153
  if (shouldUseWebpackImporter) {
154
154
  plugins.unshift(createWebpackLessPlugin(loaderContext, implementation));
155
155
  }
156
156
  plugins.unshift({
157
157
  install(lessProcessor, pluginManager) {
158
- // eslint-disable-next-line no-param-reassign
159
158
  pluginManager.webpackLoaderContext = loaderContext;
160
159
  lessOptions.pluginManager = pluginManager;
161
160
  }
@@ -178,27 +177,21 @@ function normalizeSourceMap(map) {
178
177
 
179
178
  // map.file is an optional property that provides the output filename.
180
179
  // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
181
- // eslint-disable-next-line no-param-reassign
182
- delete newMap.file;
183
180
 
184
- // eslint-disable-next-line no-param-reassign
181
+ delete newMap.file;
185
182
  newMap.sourceRoot = "";
186
183
 
187
184
  // `less` returns POSIX paths, that's why we need to transform them back to native paths.
188
- // eslint-disable-next-line no-param-reassign
189
- newMap.sources = newMap.sources.map(source => _path.default.normalize(source));
185
+
186
+ newMap.sources = newMap.sources.map(source => _nodePath.default.normalize(source));
190
187
  return newMap;
191
188
  }
192
189
  function getLessImplementation(loaderContext, implementation) {
193
190
  let resolvedImplementation = implementation;
194
191
  if (!implementation || typeof implementation === "string") {
195
192
  const lessImplPkg = implementation || "less";
196
-
197
- // eslint-disable-next-line import/no-dynamic-require, global-require
198
193
  resolvedImplementation = require(lessImplPkg);
199
194
  }
200
-
201
- // eslint-disable-next-line consistent-return
202
195
  return resolvedImplementation;
203
196
  }
204
197
  function getFileExcerptIfPossible(error) {
@@ -210,11 +203,11 @@ function getFileExcerptIfPossible(error) {
210
203
  if (typeof excerpt[0] === "undefined") {
211
204
  excerpt.shift();
212
205
  }
213
- excerpt.push(`${new Array(column).join(" ")}^`);
206
+ excerpt.push(`${" ".repeat(column)}^`);
214
207
  return excerpt;
215
208
  }
216
209
  function errorFactory(error) {
217
- const message = ["\n", ...getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), error.filename ? ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})` : ""].join("\n");
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");
218
211
  const obj = new Error(message, {
219
212
  cause: error
220
213
  });
package/package.json CHANGED
@@ -1,26 +1,35 @@
1
1
  {
2
2
  "name": "less-loader",
3
- "version": "12.2.0",
3
+ "version": "12.3.1",
4
4
  "description": "A Less loader for webpack. Compiles Less to CSS.",
5
- "license": "MIT",
6
- "repository": "webpack-contrib/less-loader",
7
- "author": "Johannes Ewald @jhnns",
8
- "homepage": "https://github.com/webpack-contrib/less-loader",
9
- "bugs": "https://github.com/webpack-contrib/less-loader/issues",
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
- "engines": {
16
- "node": ">= 18.12.0"
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=master",
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 .",
@@ -34,14 +43,47 @@
34
43
  "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage",
35
44
  "pretest": "npm run lint",
36
45
  "test": "npm run test:coverage",
37
- "prepare": "husky install && npm run build",
46
+ "prepare": "husky && npm run build",
38
47
  "release": "standard-version"
39
48
  },
40
- "files": [
41
- "dist"
42
- ],
49
+ "devDependencies": {
50
+ "@babel/cli": "^7.24.7",
51
+ "@babel/core": "^7.24.7",
52
+ "@babel/preset-env": "^7.24.7",
53
+ "@commitlint/cli": "^18.6.1",
54
+ "@commitlint/config-conventional": "^18.6.2",
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",
59
+ "cross-env": "^7.0.3",
60
+ "cspell": "^8.10.0",
61
+ "del": "^7.1.0",
62
+ "del-cli": "^5.1.0",
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",
72
+ "husky": "^9.1.3",
73
+ "jest": "^30.0.0",
74
+ "less": "^4.2.0",
75
+ "less-plugin-glob": "^3.0.0",
76
+ "lint-staged": "^15.2.7",
77
+ "memfs": "^4.9.3",
78
+ "npm-run-all": "^4.1.5",
79
+ "prettier": "^3.3.2",
80
+ "standard-version": "^9.3.1",
81
+ "strip-ansi": "^7.1.0",
82
+ "typescript-eslint": "^8.38.0",
83
+ "webpack": "^5.92.1"
84
+ },
43
85
  "peerDependencies": {
44
- "@rspack/core": "0.x || 1.x",
86
+ "@rspack/core": "0.x || ^1.0.0 || ^2.0.0-0",
45
87
  "less": "^3.5.0 || ^4.0.0",
46
88
  "webpack": "^5.0.0"
47
89
  },
@@ -53,40 +95,7 @@
53
95
  "optional": true
54
96
  }
55
97
  },
56
- "devDependencies": {
57
- "@babel/cli": "^7.23.4",
58
- "@babel/core": "^7.23.7",
59
- "@babel/preset-env": "^7.23.7",
60
- "@commitlint/cli": "^18.4.4",
61
- "@commitlint/config-conventional": "^18.4.4",
62
- "@webpack-contrib/eslint-config-webpack": "^3.0.0",
63
- "babel-jest": "^29.7.0",
64
- "cross-env": "^7.0.3",
65
- "cspell": "^8.3.2",
66
- "del": "^7.1.0",
67
- "del-cli": "^5.1.0",
68
- "eslint": "^8.56.0",
69
- "eslint-config-prettier": "^9.1.0",
70
- "eslint-plugin-import": "^2.29.1",
71
- "husky": "^8.0.3",
72
- "jest": "^29.7.0",
73
- "less": "^4.2.0",
74
- "less-plugin-glob": "^3.0.0",
75
- "lint-staged": "^15.2.0",
76
- "memfs": "^4.6.0",
77
- "npm-run-all": "^4.1.5",
78
- "prettier": "^3.2.2",
79
- "standard-version": "^9.3.1",
80
- "strip-ansi": "^7.1.0",
81
- "webpack": "^5.89.0"
82
- },
83
- "keywords": [
84
- "webpack",
85
- "loader",
86
- "less",
87
- "lesscss",
88
- "less.js",
89
- "css",
90
- "preprocessor"
91
- ]
98
+ "engines": {
99
+ "node": ">= 18.12.0"
100
+ }
92
101
  }