less-loader 10.0.1 → 11.0.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 +62 -26
- package/dist/index.js +31 -3
- package/dist/options.json +10 -5
- package/dist/utils.js +1 -1
- package/package.json +16 -15
package/README.md
CHANGED
|
@@ -21,7 +21,19 @@ A Less loader for webpack. Compiles Less to CSS.
|
|
|
21
21
|
To begin, you'll need to install `less` and `less-loader`:
|
|
22
22
|
|
|
23
23
|
```console
|
|
24
|
-
|
|
24
|
+
npm install less less-loader --save-dev
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
or
|
|
28
|
+
|
|
29
|
+
```console
|
|
30
|
+
yarn add -D less less-loader
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or
|
|
34
|
+
|
|
35
|
+
```console
|
|
36
|
+
pnpm add -D less less-loader
|
|
25
37
|
```
|
|
26
38
|
|
|
27
39
|
Then add the loader to your `webpack` config. For example:
|
|
@@ -34,7 +46,7 @@ module.exports = {
|
|
|
34
46
|
rules: [
|
|
35
47
|
{
|
|
36
48
|
test: /\.less$/i,
|
|
37
|
-
|
|
49
|
+
use: [
|
|
38
50
|
// compiles Less to CSS
|
|
39
51
|
"style-loader",
|
|
40
52
|
"css-loader",
|
|
@@ -50,22 +62,25 @@ And run `webpack` via your preferred method.
|
|
|
50
62
|
|
|
51
63
|
## Options
|
|
52
64
|
|
|
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. |
|
|
65
|
+
- **[`lessOptions`](#lessoptions)**
|
|
66
|
+
- **[`additionalData`](#additionalData)**
|
|
67
|
+
- **[`sourceMap`](#sourcemap)**
|
|
68
|
+
- **[`webpackImporter`](#webpackimporter)**
|
|
69
|
+
- **[`implementation`](#implementation)**
|
|
60
70
|
|
|
61
71
|
### `lessOptions`
|
|
62
72
|
|
|
63
|
-
Type:
|
|
73
|
+
Type:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
type lessOptions = import('less').options | ((loaderContext: LoaderContext) => import('less').options})
|
|
77
|
+
```
|
|
78
|
+
|
|
64
79
|
Default: `{ relativeUrls: true }`
|
|
65
80
|
|
|
66
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:
|
|
67
82
|
|
|
68
|
-
#### `
|
|
83
|
+
#### `object`
|
|
69
84
|
|
|
70
85
|
Use an object to pass options through to Less.
|
|
71
86
|
|
|
@@ -99,7 +114,7 @@ module.exports = {
|
|
|
99
114
|
};
|
|
100
115
|
```
|
|
101
116
|
|
|
102
|
-
#### `
|
|
117
|
+
#### `function`
|
|
103
118
|
|
|
104
119
|
Allows setting the options passed through to Less based off of the loader context.
|
|
105
120
|
|
|
@@ -141,17 +156,24 @@ module.exports = {
|
|
|
141
156
|
|
|
142
157
|
### `additionalData`
|
|
143
158
|
|
|
144
|
-
Type:
|
|
159
|
+
Type:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
type additionalData =
|
|
163
|
+
| string
|
|
164
|
+
| ((content: string, loaderContext: LoaderContext) => string);
|
|
165
|
+
```
|
|
166
|
+
|
|
145
167
|
Default: `undefined`
|
|
146
168
|
|
|
147
|
-
Prepends `Less` code
|
|
169
|
+
Prepends/Appends `Less` code to the actual entry file.
|
|
148
170
|
In this case, the `less-loader` will not override the source but just **prepend** the entry's content.
|
|
149
171
|
|
|
150
172
|
This is especially useful when some of your Less variables depend on the environment:
|
|
151
173
|
|
|
152
|
-
>
|
|
174
|
+
> 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
175
|
|
|
154
|
-
#### `
|
|
176
|
+
#### `string`
|
|
155
177
|
|
|
156
178
|
```js
|
|
157
179
|
module.exports = {
|
|
@@ -175,9 +197,9 @@ module.exports = {
|
|
|
175
197
|
};
|
|
176
198
|
```
|
|
177
199
|
|
|
178
|
-
#### `
|
|
200
|
+
#### `function`
|
|
179
201
|
|
|
180
|
-
##### Sync
|
|
202
|
+
##### `Sync`
|
|
181
203
|
|
|
182
204
|
```js
|
|
183
205
|
module.exports = {
|
|
@@ -211,7 +233,7 @@ module.exports = {
|
|
|
211
233
|
};
|
|
212
234
|
```
|
|
213
235
|
|
|
214
|
-
##### Async
|
|
236
|
+
##### `Async`
|
|
215
237
|
|
|
216
238
|
```js
|
|
217
239
|
module.exports = {
|
|
@@ -247,7 +269,12 @@ module.exports = {
|
|
|
247
269
|
|
|
248
270
|
### `sourceMap`
|
|
249
271
|
|
|
250
|
-
Type:
|
|
272
|
+
Type:
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
type sourceMap = boolean;
|
|
276
|
+
```
|
|
277
|
+
|
|
251
278
|
Default: depends on the `compiler.devtool` value
|
|
252
279
|
|
|
253
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.
|
|
@@ -283,7 +310,12 @@ module.exports = {
|
|
|
283
310
|
|
|
284
311
|
### `webpackImporter`
|
|
285
312
|
|
|
286
|
-
Type:
|
|
313
|
+
Type:
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
type webpackImporter = boolean;
|
|
317
|
+
```
|
|
318
|
+
|
|
287
319
|
Default: `true`
|
|
288
320
|
|
|
289
321
|
Enables/Disables the default `webpack` importer.
|
|
@@ -316,15 +348,19 @@ module.exports = {
|
|
|
316
348
|
|
|
317
349
|
### `implementation`
|
|
318
350
|
|
|
319
|
-
Type:
|
|
351
|
+
Type:
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
type implementation = object | string;
|
|
355
|
+
```
|
|
320
356
|
|
|
321
|
-
>
|
|
357
|
+
> less-loader compatible with Less 3 and 4 versions
|
|
322
358
|
|
|
323
359
|
The special `implementation` option determines which implementation of Less to use. Overrides the locally installed `peerDependency` version of `less`.
|
|
324
360
|
|
|
325
361
|
**This option is only really useful for downstream tooling authors to ease the Less 3-to-4 transition.**
|
|
326
362
|
|
|
327
|
-
####
|
|
363
|
+
#### `object`
|
|
328
364
|
|
|
329
365
|
**webpack.config.js**
|
|
330
366
|
|
|
@@ -350,7 +386,7 @@ module.exports = {
|
|
|
350
386
|
};
|
|
351
387
|
```
|
|
352
388
|
|
|
353
|
-
####
|
|
389
|
+
#### `string`
|
|
354
390
|
|
|
355
391
|
**webpack.config.js**
|
|
356
392
|
|
|
@@ -579,7 +615,7 @@ Bundling CSS with webpack has some nice advantages like referencing images and f
|
|
|
579
615
|
There are two possibilities to extract a style sheet from the bundle:
|
|
580
616
|
|
|
581
617
|
- [`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)
|
|
618
|
+
- [`MiniCssExtractPlugin`](https://github.com/webpack-contrib/mini-css-extract-plugin) (more complex, but works in all use-cases)
|
|
583
619
|
|
|
584
620
|
### CSS modules gotcha
|
|
585
621
|
|
package/dist/index.js
CHANGED
|
@@ -40,6 +40,26 @@ async function lessLoader(source) {
|
|
|
40
40
|
data = typeof options.additionalData === "function" ? `${await options.additionalData(data, this)}` : `${options.additionalData}\n${data}`;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
const logger = this.getLogger("less-loader");
|
|
44
|
+
const loggerListener = {
|
|
45
|
+
error(message) {
|
|
46
|
+
logger.error(message);
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
warn(message) {
|
|
50
|
+
logger.warn(message);
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
info(message) {
|
|
54
|
+
logger.log(message);
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
debug(message) {
|
|
58
|
+
logger.debug(message);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
};
|
|
62
|
+
implementation.logger.addListener(loggerListener);
|
|
43
63
|
let result;
|
|
44
64
|
|
|
45
65
|
try {
|
|
@@ -53,10 +73,13 @@ async function lessLoader(source) {
|
|
|
53
73
|
|
|
54
74
|
callback(new _LessError.default(error));
|
|
55
75
|
return;
|
|
76
|
+
} finally {
|
|
77
|
+
// Fix memory leaks in `less`
|
|
78
|
+
implementation.logger.removeListener(loggerListener);
|
|
79
|
+
delete lessOptions.pluginManager.webpackLoaderContext;
|
|
80
|
+
delete lessOptions.pluginManager;
|
|
56
81
|
}
|
|
57
82
|
|
|
58
|
-
delete lessOptions.pluginManager.webpackLoaderContext;
|
|
59
|
-
delete lessOptions.pluginManager;
|
|
60
83
|
const {
|
|
61
84
|
css,
|
|
62
85
|
imports
|
|
@@ -68,7 +91,12 @@ async function lessLoader(source) {
|
|
|
68
91
|
// Ref: https://github.com/webpack-contrib/less-loader/issues/357
|
|
69
92
|
|
|
70
93
|
|
|
71
|
-
|
|
94
|
+
const normalizedItem = _path.default.normalize(item); // Custom `importer` can return only `contents` so item will be relative
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if (_path.default.isAbsolute(normalizedItem)) {
|
|
98
|
+
this.addDependency(normalizedItem);
|
|
99
|
+
}
|
|
72
100
|
});
|
|
73
101
|
let map = typeof result.map === "string" ? JSON.parse(result.map) : result.map;
|
|
74
102
|
|
package/dist/options.json
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
"type": "object",
|
|
4
4
|
"properties": {
|
|
5
5
|
"lessOptions": {
|
|
6
|
-
"description": "Options to pass through to `Less
|
|
6
|
+
"description": "Options to pass through to `Less`.",
|
|
7
|
+
"link": "https://github.com/webpack-contrib/less-loader#lessoptions",
|
|
7
8
|
"anyOf": [
|
|
8
9
|
{
|
|
9
10
|
"type": "object",
|
|
@@ -15,7 +16,8 @@
|
|
|
15
16
|
]
|
|
16
17
|
},
|
|
17
18
|
"additionalData": {
|
|
18
|
-
"description": "Prepends/Appends `Less` code to the actual entry file
|
|
19
|
+
"description": "Prepends/Appends `Less` code to the actual entry file.",
|
|
20
|
+
"link": "https://github.com/webpack-contrib/less-loader#additionalData",
|
|
19
21
|
"anyOf": [
|
|
20
22
|
{
|
|
21
23
|
"type": "string"
|
|
@@ -26,15 +28,18 @@
|
|
|
26
28
|
]
|
|
27
29
|
},
|
|
28
30
|
"sourceMap": {
|
|
29
|
-
"description": "Enables/Disables generation of source maps
|
|
31
|
+
"description": "Enables/Disables generation of source maps.",
|
|
32
|
+
"link": "https://github.com/webpack-contrib/less-loader#sourcemap",
|
|
30
33
|
"type": "boolean"
|
|
31
34
|
},
|
|
32
35
|
"webpackImporter": {
|
|
33
|
-
"description": "Enables/Disables default `webpack` importer
|
|
36
|
+
"description": "Enables/Disables default `webpack` importer.",
|
|
37
|
+
"link": "https://github.com/webpack-contrib/less-loader#webpackimporter",
|
|
34
38
|
"type": "boolean"
|
|
35
39
|
},
|
|
36
40
|
"implementation": {
|
|
37
|
-
"description": "The implementation of the `Less` to be used
|
|
41
|
+
"description": "The implementation of the `Less` to be used.",
|
|
42
|
+
"link": "https://github.com/webpack-contrib/less-loader#implementation",
|
|
38
43
|
"anyOf": [
|
|
39
44
|
{
|
|
40
45
|
"type": "string"
|
package/dist/utils.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getLessImplementation = getLessImplementation;
|
|
6
7
|
exports.getLessOptions = getLessOptions;
|
|
7
8
|
exports.isUnsupportedUrl = isUnsupportedUrl;
|
|
8
9
|
exports.normalizeSourceMap = normalizeSourceMap;
|
|
9
|
-
exports.getLessImplementation = getLessImplementation;
|
|
10
10
|
|
|
11
11
|
var _path = _interopRequireDefault(require("path"));
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "less-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.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",
|
|
@@ -46,27 +46,28 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/cli": "^7.14.5",
|
|
48
48
|
"@babel/core": "^7.14.6",
|
|
49
|
-
"@babel/preset-env": "^7.14.
|
|
50
|
-
"@commitlint/cli": "^
|
|
51
|
-
"@commitlint/config-conventional": "^
|
|
49
|
+
"@babel/preset-env": "^7.14.7",
|
|
50
|
+
"@commitlint/cli": "^17.0.0",
|
|
51
|
+
"@commitlint/config-conventional": "^17.0.0",
|
|
52
52
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
53
|
-
"babel-jest": "^
|
|
53
|
+
"babel-jest": "^28.1.0",
|
|
54
54
|
"cross-env": "^7.0.3",
|
|
55
55
|
"del": "^6.0.0",
|
|
56
|
-
"del-cli": "^4.0.
|
|
57
|
-
"eslint": "^
|
|
56
|
+
"del-cli": "^4.0.1",
|
|
57
|
+
"eslint": "^8.15.0",
|
|
58
58
|
"eslint-config-prettier": "^8.3.0",
|
|
59
|
-
"eslint-plugin-import": "^2.
|
|
60
|
-
"husky": "^
|
|
61
|
-
"jest": "^
|
|
59
|
+
"eslint-plugin-import": "^2.24.1",
|
|
60
|
+
"husky": "^8.0.1",
|
|
61
|
+
"jest": "^28.1.0",
|
|
62
62
|
"less": "^4.1.1",
|
|
63
|
-
"
|
|
63
|
+
"less-plugin-glob": "^3.0.0",
|
|
64
|
+
"lint-staged": "^12.4.1",
|
|
64
65
|
"memfs": "^3.2.2",
|
|
65
66
|
"npm-run-all": "^4.1.5",
|
|
66
|
-
"prettier": "^2.3.
|
|
67
|
-
"standard-version": "^9.3.
|
|
67
|
+
"prettier": "^2.3.2",
|
|
68
|
+
"standard-version": "^9.3.1",
|
|
68
69
|
"strip-ansi": "^7.0.0",
|
|
69
|
-
"webpack": "^5.
|
|
70
|
+
"webpack": "^5.51.1"
|
|
70
71
|
},
|
|
71
72
|
"keywords": [
|
|
72
73
|
"webpack",
|