less-loader 10.2.0 → 11.1.0
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 +68 -40
- package/dist/utils.js +1 -1
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
[![npm][npm]][npm-url]
|
|
8
8
|
[![node][node]][node-url]
|
|
9
|
-
[![deps][deps]][deps-url]
|
|
10
9
|
[![tests][tests]][tests-url]
|
|
11
10
|
[![cover][cover]][cover-url]
|
|
12
11
|
[![chat][chat]][chat-url]
|
|
@@ -21,7 +20,19 @@ A Less loader for webpack. Compiles Less to CSS.
|
|
|
21
20
|
To begin, you'll need to install `less` and `less-loader`:
|
|
22
21
|
|
|
23
22
|
```console
|
|
24
|
-
|
|
23
|
+
npm install less less-loader --save-dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
or
|
|
27
|
+
|
|
28
|
+
```console
|
|
29
|
+
yarn add -D less less-loader
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
or
|
|
33
|
+
|
|
34
|
+
```console
|
|
35
|
+
pnpm add -D less less-loader
|
|
25
36
|
```
|
|
26
37
|
|
|
27
38
|
Then add the loader to your `webpack` config. For example:
|
|
@@ -34,7 +45,7 @@ module.exports = {
|
|
|
34
45
|
rules: [
|
|
35
46
|
{
|
|
36
47
|
test: /\.less$/i,
|
|
37
|
-
|
|
48
|
+
use: [
|
|
38
49
|
// compiles Less to CSS
|
|
39
50
|
"style-loader",
|
|
40
51
|
"css-loader",
|
|
@@ -50,22 +61,25 @@ And run `webpack` via your preferred method.
|
|
|
50
61
|
|
|
51
62
|
## Options
|
|
52
63
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
| **[`webpackImporter`](#webpackimporter)** | `{Boolean}` | `true` | Enables/Disables the default Webpack importer. |
|
|
59
|
-
| **[`implementation`](#implementation)** | `{Object\|String}` | `less` | Setup Less implementation to use. |
|
|
64
|
+
- **[`lessOptions`](#lessoptions)**
|
|
65
|
+
- **[`additionalData`](#additionalData)**
|
|
66
|
+
- **[`sourceMap`](#sourcemap)**
|
|
67
|
+
- **[`webpackImporter`](#webpackimporter)**
|
|
68
|
+
- **[`implementation`](#implementation)**
|
|
60
69
|
|
|
61
70
|
### `lessOptions`
|
|
62
71
|
|
|
63
|
-
Type:
|
|
72
|
+
Type:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
type lessOptions = import('less').options | ((loaderContext: LoaderContext) => import('less').options})
|
|
76
|
+
```
|
|
77
|
+
|
|
64
78
|
Default: `{ relativeUrls: true }`
|
|
65
79
|
|
|
66
80
|
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:
|
|
67
81
|
|
|
68
|
-
#### `
|
|
82
|
+
#### `object`
|
|
69
83
|
|
|
70
84
|
Use an object to pass options through to Less.
|
|
71
85
|
|
|
@@ -99,7 +113,7 @@ module.exports = {
|
|
|
99
113
|
};
|
|
100
114
|
```
|
|
101
115
|
|
|
102
|
-
#### `
|
|
116
|
+
#### `function`
|
|
103
117
|
|
|
104
118
|
Allows setting the options passed through to Less based off of the loader context.
|
|
105
119
|
|
|
@@ -141,17 +155,24 @@ module.exports = {
|
|
|
141
155
|
|
|
142
156
|
### `additionalData`
|
|
143
157
|
|
|
144
|
-
Type:
|
|
158
|
+
Type:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
type additionalData =
|
|
162
|
+
| string
|
|
163
|
+
| ((content: string, loaderContext: LoaderContext) => string);
|
|
164
|
+
```
|
|
165
|
+
|
|
145
166
|
Default: `undefined`
|
|
146
167
|
|
|
147
|
-
Prepends `Less` code
|
|
168
|
+
Prepends/Appends `Less` code to the actual entry file.
|
|
148
169
|
In this case, the `less-loader` will not override the source but just **prepend** the entry's content.
|
|
149
170
|
|
|
150
171
|
This is especially useful when some of your Less variables depend on the environment:
|
|
151
172
|
|
|
152
|
-
>
|
|
173
|
+
> 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.
|
|
153
174
|
|
|
154
|
-
#### `
|
|
175
|
+
#### `string`
|
|
155
176
|
|
|
156
177
|
```js
|
|
157
178
|
module.exports = {
|
|
@@ -175,9 +196,9 @@ module.exports = {
|
|
|
175
196
|
};
|
|
176
197
|
```
|
|
177
198
|
|
|
178
|
-
#### `
|
|
199
|
+
#### `function`
|
|
179
200
|
|
|
180
|
-
##### Sync
|
|
201
|
+
##### `Sync`
|
|
181
202
|
|
|
182
203
|
```js
|
|
183
204
|
module.exports = {
|
|
@@ -211,7 +232,7 @@ module.exports = {
|
|
|
211
232
|
};
|
|
212
233
|
```
|
|
213
234
|
|
|
214
|
-
##### Async
|
|
235
|
+
##### `Async`
|
|
215
236
|
|
|
216
237
|
```js
|
|
217
238
|
module.exports = {
|
|
@@ -247,7 +268,12 @@ module.exports = {
|
|
|
247
268
|
|
|
248
269
|
### `sourceMap`
|
|
249
270
|
|
|
250
|
-
Type:
|
|
271
|
+
Type:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
type sourceMap = boolean;
|
|
275
|
+
```
|
|
276
|
+
|
|
251
277
|
Default: depends on the `compiler.devtool` value
|
|
252
278
|
|
|
253
279
|
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.
|
|
@@ -283,12 +309,17 @@ module.exports = {
|
|
|
283
309
|
|
|
284
310
|
### `webpackImporter`
|
|
285
311
|
|
|
286
|
-
Type:
|
|
312
|
+
Type:
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
type webpackImporter = boolean;
|
|
316
|
+
```
|
|
317
|
+
|
|
287
318
|
Default: `true`
|
|
288
319
|
|
|
289
320
|
Enables/Disables the default `webpack` importer.
|
|
290
321
|
|
|
291
|
-
This can improve performance in some cases. Use it with caution because aliases and `@import`
|
|
322
|
+
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.
|
|
292
323
|
|
|
293
324
|
**webpack.config.js**
|
|
294
325
|
|
|
@@ -316,15 +347,19 @@ module.exports = {
|
|
|
316
347
|
|
|
317
348
|
### `implementation`
|
|
318
349
|
|
|
319
|
-
Type:
|
|
350
|
+
Type:
|
|
320
351
|
|
|
321
|
-
|
|
352
|
+
```ts
|
|
353
|
+
type implementation = object | string;
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
> less-loader compatible with Less 3 and 4 versions
|
|
322
357
|
|
|
323
358
|
The special `implementation` option determines which implementation of Less to use. Overrides the locally installed `peerDependency` version of `less`.
|
|
324
359
|
|
|
325
360
|
**This option is only really useful for downstream tooling authors to ease the Less 3-to-4 transition.**
|
|
326
361
|
|
|
327
|
-
####
|
|
362
|
+
#### `object`
|
|
328
363
|
|
|
329
364
|
**webpack.config.js**
|
|
330
365
|
|
|
@@ -350,7 +385,7 @@ module.exports = {
|
|
|
350
385
|
};
|
|
351
386
|
```
|
|
352
387
|
|
|
353
|
-
####
|
|
388
|
+
#### `string`
|
|
354
389
|
|
|
355
390
|
**webpack.config.js**
|
|
356
391
|
|
|
@@ -451,7 +486,7 @@ Usually, it's recommended to extract the style sheets into a dedicated file in p
|
|
|
451
486
|
|
|
452
487
|
### Imports
|
|
453
488
|
|
|
454
|
-
First we try to use built-in `less` resolve logic, then `webpack` resolve logic
|
|
489
|
+
First we try to use built-in `less` resolve logic, then `webpack` resolve logic.
|
|
455
490
|
|
|
456
491
|
#### Webpack Resolver
|
|
457
492
|
|
|
@@ -464,12 +499,7 @@ Thus you can import your Less modules from `node_modules`.
|
|
|
464
499
|
```
|
|
465
500
|
|
|
466
501
|
Using `~` is deprecated and can be removed from your code (**we recommend it**), but we still support it for historical reasons.
|
|
467
|
-
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/#
|
|
468
|
-
Just prepend them with a `~` which tells webpack to look up the [`modules`](https://webpack.js.org/configuration/resolve/#resolve-modules).
|
|
469
|
-
|
|
470
|
-
```css
|
|
471
|
-
@import "~bootstrap/less/bootstrap";
|
|
472
|
-
```
|
|
502
|
+
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).
|
|
473
503
|
|
|
474
504
|
Default resolver options can be modified by [`resolve.byDependency`](https://webpack.js.org/configuration/resolve/#resolvebydependency):
|
|
475
505
|
|
|
@@ -497,8 +527,6 @@ module.exports = {
|
|
|
497
527
|
};
|
|
498
528
|
```
|
|
499
529
|
|
|
500
|
-
It's important to only prepend it with `~`, because `~/` resolves to the home-directory. webpack needs to distinguish between `bootstrap` and `~bootstrap`, because CSS and Less files have no special syntax for importing relative files. Writing `@import "file"` is the same as `@import "./file";`
|
|
501
|
-
|
|
502
530
|
#### Less Resolver
|
|
503
531
|
|
|
504
532
|
If you specify the `paths` option, modules will be searched in the given `paths`. This is `less` default behavior. `paths` should be an array with absolute paths:
|
|
@@ -558,7 +586,9 @@ module.exports = {
|
|
|
558
586
|
};
|
|
559
587
|
```
|
|
560
588
|
|
|
561
|
-
>
|
|
589
|
+
> **Note**
|
|
590
|
+
>
|
|
591
|
+
> 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.
|
|
562
592
|
|
|
563
593
|
```js
|
|
564
594
|
module.exports = {
|
|
@@ -579,7 +609,7 @@ Bundling CSS with webpack has some nice advantages like referencing images and f
|
|
|
579
609
|
There are two possibilities to extract a style sheet from the bundle:
|
|
580
610
|
|
|
581
611
|
- [`extract-loader`](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
|
|
582
|
-
- [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin) (more complex, but works in all use-cases)
|
|
612
|
+
- [`MiniCssExtractPlugin`](https://github.com/webpack-contrib/mini-css-extract-plugin) (more complex, but works in all use-cases)
|
|
583
613
|
|
|
584
614
|
### CSS modules gotcha
|
|
585
615
|
|
|
@@ -599,8 +629,6 @@ Please take a moment to read our contributing guidelines if you haven't yet done
|
|
|
599
629
|
[npm-url]: https://npmjs.com/package/less-loader
|
|
600
630
|
[node]: https://img.shields.io/node/v/less-loader.svg
|
|
601
631
|
[node-url]: https://nodejs.org
|
|
602
|
-
[deps]: https://david-dm.org/webpack-contrib/less-loader.svg
|
|
603
|
-
[deps-url]: https://david-dm.org/webpack-contrib/less-loader
|
|
604
632
|
[tests]: https://github.com/webpack-contrib/less-loader/workflows/less-loader/badge.svg
|
|
605
633
|
[tests-url]: https://github.com/webpack-contrib/less-loader/actions
|
|
606
634
|
[cover]: https://codecov.io/gh/webpack-contrib/less-loader/branch/master/graph/badge.svg
|
package/dist/utils.js
CHANGED
|
@@ -42,7 +42,7 @@ const MODULE_REQUEST_REGEX = /^[^?]*~/;
|
|
|
42
42
|
function createWebpackLessPlugin(loaderContext, implementation) {
|
|
43
43
|
const resolve = loaderContext.getResolve({
|
|
44
44
|
dependencyType: "less",
|
|
45
|
-
conditionNames: ["less", "style"],
|
|
45
|
+
conditionNames: ["less", "style", "..."],
|
|
46
46
|
mainFields: ["less", "style", "main", "..."],
|
|
47
47
|
mainFiles: ["index", "..."],
|
|
48
48
|
extensions: [".less", ".css"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "less-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"description": "A Less loader for webpack. Compiles Less to CSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/less-loader",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"main": "dist/cjs.js",
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
16
|
+
"node": ">= 14.15.0"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"start": "npm run build -- -w",
|
|
@@ -44,30 +44,30 @@
|
|
|
44
44
|
"klona": "^2.0.4"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@babel/cli": "^7.
|
|
48
|
-
"@babel/core": "^7.
|
|
49
|
-
"@babel/preset-env": "^7.
|
|
50
|
-
"@commitlint/cli": "^
|
|
51
|
-
"@commitlint/config-conventional": "^
|
|
47
|
+
"@babel/cli": "^7.19.3",
|
|
48
|
+
"@babel/core": "^7.19.3",
|
|
49
|
+
"@babel/preset-env": "^7.19.3",
|
|
50
|
+
"@commitlint/cli": "^17.1.2",
|
|
51
|
+
"@commitlint/config-conventional": "^17.1.0",
|
|
52
52
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
53
|
-
"babel-jest": "^
|
|
53
|
+
"babel-jest": "^29.1.2",
|
|
54
54
|
"cross-env": "^7.0.3",
|
|
55
|
-
"del": "^6.
|
|
55
|
+
"del": "^6.1.1",
|
|
56
56
|
"del-cli": "^4.0.1",
|
|
57
|
-
"eslint": "^
|
|
57
|
+
"eslint": "^8.24.0",
|
|
58
58
|
"eslint-config-prettier": "^8.3.0",
|
|
59
59
|
"eslint-plugin-import": "^2.24.1",
|
|
60
|
-
"husky": "^
|
|
61
|
-
"jest": "^
|
|
62
|
-
"less": "^4.1.
|
|
63
|
-
"less-plugin-glob": "^
|
|
64
|
-
"lint-staged": "^
|
|
65
|
-
"memfs": "^3.
|
|
60
|
+
"husky": "^8.0.1",
|
|
61
|
+
"jest": "^29.1.2",
|
|
62
|
+
"less": "^4.1.3",
|
|
63
|
+
"less-plugin-glob": "^2.0.2",
|
|
64
|
+
"lint-staged": "^12.5.0",
|
|
65
|
+
"memfs": "^3.4.7",
|
|
66
66
|
"npm-run-all": "^4.1.5",
|
|
67
|
-
"prettier": "^2.
|
|
67
|
+
"prettier": "^2.7.1",
|
|
68
68
|
"standard-version": "^9.3.1",
|
|
69
69
|
"strip-ansi": "^7.0.0",
|
|
70
|
-
"webpack": "^5.
|
|
70
|
+
"webpack": "^5.74.0"
|
|
71
71
|
},
|
|
72
72
|
"keywords": [
|
|
73
73
|
"webpack",
|