less-loader 7.0.2 → 7.3.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/CHANGELOG.md +28 -0
- package/README.md +117 -69
- package/dist/LessError.js +4 -4
- package/dist/cjs.js +1 -1
- package/dist/index.js +8 -8
- package/dist/options.json +4 -0
- package/dist/utils.js +14 -18
- package/package.json +17 -18
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [7.3.0](https://github.com/webpack-contrib/less-loader/compare/v7.2.1...v7.3.0) (2021-01-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* added the `implementation` option ([84d957c](https://github.com/webpack-contrib/less-loader/commit/84d957cfe4fbd6c97619c647d0dd0917b99408ae))
|
|
11
|
+
|
|
12
|
+
### [7.2.1](https://github.com/webpack-contrib/less-loader/compare/v7.2.0...v7.2.1) (2020-12-28)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* errors from less ([#401](https://github.com/webpack-contrib/less-loader/issues/401)) ([ce31aca](https://github.com/webpack-contrib/less-loader/commit/ce31aca7aada70a8cc267449954ab38b642cd4ba))
|
|
18
|
+
|
|
19
|
+
## [7.2.0](https://github.com/webpack-contrib/less-loader/compare/v7.1.0...v7.2.0) (2020-12-23)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* add less ^4.0 to peerDependencies ([#398](https://github.com/webpack-contrib/less-loader/issues/398)) ([3d1abb7](https://github.com/webpack-contrib/less-loader/commit/3d1abb7be041e44fce59b2109d02eada1451a4e4))
|
|
25
|
+
|
|
26
|
+
## [7.1.0](https://github.com/webpack-contrib/less-loader/compare/v7.0.2...v7.1.0) (2020-11-11)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* allow the `additionalData` to be async ([#391](https://github.com/webpack-contrib/less-loader/issues/391)) ([62c6934](https://github.com/webpack-contrib/less-loader/commit/62c6934367eb4dd0d4f3155ed2bb5f3e065aafba))
|
|
32
|
+
|
|
5
33
|
### [7.0.2](https://github.com/webpack-contrib/less-loader/compare/v7.0.1...v7.0.2) (2020-10-09)
|
|
6
34
|
|
|
7
35
|
### Chore
|
package/README.md
CHANGED
|
@@ -33,8 +33,8 @@ module.exports = {
|
|
|
33
33
|
module: {
|
|
34
34
|
rules: [
|
|
35
35
|
{
|
|
36
|
-
test: /\.less
|
|
37
|
-
loader:
|
|
36
|
+
test: /\.less$/i,
|
|
37
|
+
loader: "less-loader", // compiles Less to CSS
|
|
38
38
|
},
|
|
39
39
|
],
|
|
40
40
|
},
|
|
@@ -51,6 +51,7 @@ And run `webpack` via your preferred method.
|
|
|
51
51
|
| **[`additionalData`](#additionalData)** | `{String\|Function}` | `undefined` | Prepends/Appends `Less` code to the actual entry file. |
|
|
52
52
|
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps. |
|
|
53
53
|
| **[`webpackImporter`](#webpackimporter)** | `{Boolean}` | `true` | Enables/Disables the default Webpack importer. |
|
|
54
|
+
| **[`implementation`](#implementation)** | `{Object}` | `less` | Setup Less implementation to use. |
|
|
54
55
|
|
|
55
56
|
### `lessOptions`
|
|
56
57
|
|
|
@@ -70,16 +71,16 @@ module.exports = {
|
|
|
70
71
|
module: {
|
|
71
72
|
rules: [
|
|
72
73
|
{
|
|
73
|
-
test: /\.less
|
|
74
|
+
test: /\.less$/i,
|
|
74
75
|
use: [
|
|
75
76
|
{
|
|
76
|
-
loader:
|
|
77
|
+
loader: "style-loader",
|
|
77
78
|
},
|
|
78
79
|
{
|
|
79
|
-
loader:
|
|
80
|
+
loader: "css-loader",
|
|
80
81
|
},
|
|
81
82
|
{
|
|
82
|
-
loader:
|
|
83
|
+
loader: "less-loader",
|
|
83
84
|
options: {
|
|
84
85
|
lessOptions: {
|
|
85
86
|
strictMath: true,
|
|
@@ -102,26 +103,26 @@ module.exports = {
|
|
|
102
103
|
module: {
|
|
103
104
|
rules: [
|
|
104
105
|
{
|
|
105
|
-
test: /\.less
|
|
106
|
+
test: /\.less$/i,
|
|
106
107
|
use: [
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
"style-loader",
|
|
109
|
+
"css-loader",
|
|
109
110
|
{
|
|
110
|
-
loader:
|
|
111
|
+
loader: "less-loader",
|
|
111
112
|
options: {
|
|
112
113
|
lessOptions: (loaderContext) => {
|
|
113
114
|
// More information about available properties https://webpack.js.org/api/loaders/
|
|
114
115
|
const { resourcePath, rootContext } = loaderContext;
|
|
115
116
|
const relativePath = path.relative(rootContext, resourcePath);
|
|
116
117
|
|
|
117
|
-
if (relativePath ===
|
|
118
|
+
if (relativePath === "styles/foo.less") {
|
|
118
119
|
return {
|
|
119
|
-
paths: [
|
|
120
|
+
paths: ["absolute/path/c", "absolute/path/d"],
|
|
120
121
|
};
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
return {
|
|
124
|
-
paths: [
|
|
125
|
+
paths: ["absolute/path/a", "absolute/path/b"],
|
|
125
126
|
};
|
|
126
127
|
},
|
|
127
128
|
},
|
|
@@ -152,12 +153,12 @@ module.exports = {
|
|
|
152
153
|
module: {
|
|
153
154
|
rules: [
|
|
154
155
|
{
|
|
155
|
-
test: /\.less
|
|
156
|
+
test: /\.less$/i,
|
|
156
157
|
use: [
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
"style-loader",
|
|
159
|
+
"css-loader",
|
|
159
160
|
{
|
|
160
|
-
loader:
|
|
161
|
+
loader: "less-loader",
|
|
161
162
|
options: {
|
|
162
163
|
additionalData: `@env: ${process.env.NODE_ENV};`,
|
|
163
164
|
},
|
|
@@ -171,28 +172,64 @@ module.exports = {
|
|
|
171
172
|
|
|
172
173
|
#### `Function`
|
|
173
174
|
|
|
175
|
+
##### Sync
|
|
176
|
+
|
|
174
177
|
```js
|
|
175
178
|
module.exports = {
|
|
176
179
|
module: {
|
|
177
180
|
rules: [
|
|
178
181
|
{
|
|
179
|
-
test: /\.less
|
|
182
|
+
test: /\.less$/i,
|
|
180
183
|
use: [
|
|
181
|
-
|
|
182
|
-
|
|
184
|
+
"style-loader",
|
|
185
|
+
"css-loader",
|
|
183
186
|
{
|
|
184
|
-
loader:
|
|
187
|
+
loader: "less-loader",
|
|
185
188
|
options: {
|
|
186
189
|
additionalData: (content, loaderContext) => {
|
|
187
190
|
// More information about available properties https://webpack.js.org/api/loaders/
|
|
188
191
|
const { resourcePath, rootContext } = loaderContext;
|
|
189
192
|
const relativePath = path.relative(rootContext, resourcePath);
|
|
190
193
|
|
|
191
|
-
if (relativePath ===
|
|
192
|
-
return
|
|
194
|
+
if (relativePath === "styles/foo.less") {
|
|
195
|
+
return "@value: 100px;" + content;
|
|
193
196
|
}
|
|
194
197
|
|
|
195
|
-
return
|
|
198
|
+
return "@value: 200px;" + content;
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
##### Async
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
module.exports = {
|
|
213
|
+
module: {
|
|
214
|
+
rules: [
|
|
215
|
+
{
|
|
216
|
+
test: /\.less$/i,
|
|
217
|
+
use: [
|
|
218
|
+
"style-loader",
|
|
219
|
+
"css-loader",
|
|
220
|
+
{
|
|
221
|
+
loader: "less-loader",
|
|
222
|
+
options: {
|
|
223
|
+
additionalData: async (content, loaderContext) => {
|
|
224
|
+
// More information about available properties https://webpack.js.org/api/loaders/
|
|
225
|
+
const { resourcePath, rootContext } = loaderContext;
|
|
226
|
+
const relativePath = path.relative(rootContext, resourcePath);
|
|
227
|
+
|
|
228
|
+
if (relativePath === "styles/foo.less") {
|
|
229
|
+
return "@value: 100px;" + content;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return "@value: 200px;" + content;
|
|
196
233
|
},
|
|
197
234
|
},
|
|
198
235
|
},
|
|
@@ -219,15 +256,15 @@ module.exports = {
|
|
|
219
256
|
{
|
|
220
257
|
test: /\.less$/i,
|
|
221
258
|
use: [
|
|
222
|
-
|
|
259
|
+
"style-loader",
|
|
223
260
|
{
|
|
224
|
-
loader:
|
|
261
|
+
loader: "css-loader",
|
|
225
262
|
options: {
|
|
226
263
|
sourceMap: true,
|
|
227
264
|
},
|
|
228
265
|
},
|
|
229
266
|
{
|
|
230
|
-
loader:
|
|
267
|
+
loader: "less-loader",
|
|
231
268
|
options: {
|
|
232
269
|
sourceMap: true,
|
|
233
270
|
},
|
|
@@ -257,10 +294,10 @@ module.exports = {
|
|
|
257
294
|
{
|
|
258
295
|
test: /\.less$/i,
|
|
259
296
|
use: [
|
|
260
|
-
|
|
261
|
-
|
|
297
|
+
"style-loader",
|
|
298
|
+
"css-loader",
|
|
262
299
|
{
|
|
263
|
-
loader:
|
|
300
|
+
loader: "less-loader",
|
|
264
301
|
options: {
|
|
265
302
|
webpackImporter: false,
|
|
266
303
|
},
|
|
@@ -272,6 +309,40 @@ module.exports = {
|
|
|
272
309
|
};
|
|
273
310
|
```
|
|
274
311
|
|
|
312
|
+
### `implementation`
|
|
313
|
+
|
|
314
|
+
Type: `Object`
|
|
315
|
+
|
|
316
|
+
> ⚠ less-loader compatible with Less 3 and 4 versions
|
|
317
|
+
|
|
318
|
+
The special `implementation` option determines which implementation of Less to use. Overrides the locally installed `peerDependency` version of `less`.
|
|
319
|
+
|
|
320
|
+
**This option is only really useful for downstream tooling authors to ease the Less 3-to-4 transition.**
|
|
321
|
+
|
|
322
|
+
**webpack.config.js**
|
|
323
|
+
|
|
324
|
+
```js
|
|
325
|
+
module.exports = {
|
|
326
|
+
module: {
|
|
327
|
+
rules: [
|
|
328
|
+
{
|
|
329
|
+
test: /\.less$/i,
|
|
330
|
+
use: [
|
|
331
|
+
"style-loader",
|
|
332
|
+
"css-loader",
|
|
333
|
+
{
|
|
334
|
+
loader: "less-loader",
|
|
335
|
+
options: {
|
|
336
|
+
implementation: require("less"),
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
],
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
```
|
|
345
|
+
|
|
275
346
|
## Examples
|
|
276
347
|
|
|
277
348
|
### Normal usage
|
|
@@ -285,16 +356,16 @@ module.exports = {
|
|
|
285
356
|
module: {
|
|
286
357
|
rules: [
|
|
287
358
|
{
|
|
288
|
-
test: /\.less
|
|
359
|
+
test: /\.less$/i,
|
|
289
360
|
use: [
|
|
290
361
|
{
|
|
291
|
-
loader:
|
|
362
|
+
loader: "style-loader", // creates style nodes from JS strings
|
|
292
363
|
},
|
|
293
364
|
{
|
|
294
|
-
loader:
|
|
365
|
+
loader: "css-loader", // translates CSS into CommonJS
|
|
295
366
|
},
|
|
296
367
|
{
|
|
297
|
-
loader:
|
|
368
|
+
loader: "less-loader", // compiles Less to CSS
|
|
298
369
|
},
|
|
299
370
|
],
|
|
300
371
|
},
|
|
@@ -313,21 +384,21 @@ To enable sourcemaps for CSS, you'll need to pass the `sourceMap` property in th
|
|
|
313
384
|
|
|
314
385
|
```javascript
|
|
315
386
|
module.exports = {
|
|
316
|
-
devtool:
|
|
387
|
+
devtool: "source-map", // any "source-map"-like devtool is possible
|
|
317
388
|
module: {
|
|
318
389
|
rules: [
|
|
319
390
|
{
|
|
320
|
-
test: /\.less
|
|
391
|
+
test: /\.less$/i,
|
|
321
392
|
use: [
|
|
322
|
-
|
|
393
|
+
"style-loader",
|
|
323
394
|
{
|
|
324
|
-
loader:
|
|
395
|
+
loader: "css-loader",
|
|
325
396
|
options: {
|
|
326
397
|
sourceMap: true,
|
|
327
398
|
},
|
|
328
399
|
},
|
|
329
400
|
{
|
|
330
|
-
loader:
|
|
401
|
+
loader: "less-loader",
|
|
331
402
|
options: {
|
|
332
403
|
sourceMap: true,
|
|
333
404
|
},
|
|
@@ -354,34 +425,11 @@ Starting with `less-loader` 4, you can now choose between Less' builtin resolver
|
|
|
354
425
|
webpack provides an [advanced mechanism to resolve files](https://webpack.js.org/configuration/resolve/). The `less-loader` applies a Less plugin that passes all queries to the webpack resolver. Thus you can import your Less modules from `node_modules`. Just prepend them with a `~` which tells webpack to look up the [`modules`](https://webpack.js.org/configuration/resolve/#resolve-modules).
|
|
355
426
|
|
|
356
427
|
```css
|
|
357
|
-
@import
|
|
428
|
+
@import "~bootstrap/less/bootstrap";
|
|
358
429
|
```
|
|
359
430
|
|
|
360
431
|
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";`
|
|
361
432
|
|
|
362
|
-
##### Non-Less imports
|
|
363
|
-
|
|
364
|
-
Using webpack's resolver, you can import any file type. You just need a loader that exports valid Less code. Often, you will also want to set the `issuer` condition to ensure that this rule is only applied on imports originating from Less files:
|
|
365
|
-
|
|
366
|
-
```js
|
|
367
|
-
// webpack.config.js
|
|
368
|
-
module.exports = {
|
|
369
|
-
module: {
|
|
370
|
-
rules: [
|
|
371
|
-
{
|
|
372
|
-
test: /\.js$/,
|
|
373
|
-
issuer: /\.less$/,
|
|
374
|
-
use: [
|
|
375
|
-
{
|
|
376
|
-
loader: 'js-to-less-loader',
|
|
377
|
-
},
|
|
378
|
-
],
|
|
379
|
-
},
|
|
380
|
-
],
|
|
381
|
-
},
|
|
382
|
-
};
|
|
383
|
-
```
|
|
384
|
-
|
|
385
433
|
#### Less resolver
|
|
386
434
|
|
|
387
435
|
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:
|
|
@@ -393,19 +441,19 @@ module.exports = {
|
|
|
393
441
|
module: {
|
|
394
442
|
rules: [
|
|
395
443
|
{
|
|
396
|
-
test: /\.less
|
|
444
|
+
test: /\.less$/i,
|
|
397
445
|
use: [
|
|
398
446
|
{
|
|
399
|
-
loader:
|
|
447
|
+
loader: "style-loader",
|
|
400
448
|
},
|
|
401
449
|
{
|
|
402
|
-
loader:
|
|
450
|
+
loader: "css-loader",
|
|
403
451
|
},
|
|
404
452
|
{
|
|
405
|
-
loader:
|
|
453
|
+
loader: "less-loader",
|
|
406
454
|
options: {
|
|
407
455
|
lessOptions: {
|
|
408
|
-
paths: [path.resolve(__dirname,
|
|
456
|
+
paths: [path.resolve(__dirname, "node_modules")],
|
|
409
457
|
},
|
|
410
458
|
},
|
|
411
459
|
},
|
|
@@ -445,7 +493,7 @@ module.exports = {
|
|
|
445
493
|
```js
|
|
446
494
|
module.exports = {
|
|
447
495
|
install: function (less, pluginManager, functions) {
|
|
448
|
-
functions.add(
|
|
496
|
+
functions.add("pi", function () {
|
|
449
497
|
// Loader context is available in `less.webpackLoaderContext`
|
|
450
498
|
|
|
451
499
|
return Math.PI;
|
package/dist/LessError.js
CHANGED
|
@@ -12,23 +12,23 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
class LessError extends Error {
|
|
13
13
|
constructor(error) {
|
|
14
14
|
super();
|
|
15
|
-
this.message = [
|
|
15
|
+
this.message = ["\n", ...LessError.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");
|
|
16
16
|
this.hideStack = true;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
static getFileExcerptIfPossible(lessError) {
|
|
20
|
-
if (typeof lessError.extract ===
|
|
20
|
+
if (typeof lessError.extract === "undefined") {
|
|
21
21
|
return [];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const excerpt = lessError.extract.slice(0, 2);
|
|
25
25
|
const column = Math.max(lessError.column - 1, 0);
|
|
26
26
|
|
|
27
|
-
if (typeof excerpt[0] ===
|
|
27
|
+
if (typeof excerpt[0] === "undefined") {
|
|
28
28
|
excerpt.shift();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
excerpt.push(`${new Array(column).join(
|
|
31
|
+
excerpt.push(`${new Array(column).join(" ")}^`);
|
|
32
32
|
return excerpt;
|
|
33
33
|
}
|
|
34
34
|
|
package/dist/cjs.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,12 +24,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
24
24
|
async function lessLoader(source) {
|
|
25
25
|
const options = (0, _loaderUtils.getOptions)(this);
|
|
26
26
|
(0, _schemaUtils.validate)(_options.default, options, {
|
|
27
|
-
name:
|
|
28
|
-
baseDataPath:
|
|
27
|
+
name: "Less Loader",
|
|
28
|
+
baseDataPath: "options"
|
|
29
29
|
});
|
|
30
30
|
const callback = this.async();
|
|
31
31
|
const lessOptions = (0, _utils.getLessOptions)(this, options);
|
|
32
|
-
const useSourceMap = typeof options.sourceMap ===
|
|
32
|
+
const useSourceMap = typeof options.sourceMap === "boolean" ? options.sourceMap : this.sourceMap;
|
|
33
33
|
|
|
34
34
|
if (useSourceMap) {
|
|
35
35
|
lessOptions.sourceMap = {
|
|
@@ -39,17 +39,17 @@ async function lessLoader(source) {
|
|
|
39
39
|
|
|
40
40
|
let data = source;
|
|
41
41
|
|
|
42
|
-
if (typeof options.additionalData !==
|
|
43
|
-
data = typeof options.additionalData ===
|
|
42
|
+
if (typeof options.additionalData !== "undefined") {
|
|
43
|
+
data = typeof options.additionalData === "function" ? `${await options.additionalData(data, this)}` : `${options.additionalData}\n${data}`;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
let result;
|
|
47
47
|
|
|
48
48
|
try {
|
|
49
|
-
result = await _less.default.render(data, lessOptions);
|
|
49
|
+
result = await (options.implementation || _less.default).render(data, lessOptions);
|
|
50
50
|
} catch (error) {
|
|
51
51
|
if (error.filename) {
|
|
52
|
-
// `less`
|
|
52
|
+
// `less` returns forward slashes on windows when `webpack` resolver return an absolute windows path in `WebpackFileManager`
|
|
53
53
|
// Ref: https://github.com/webpack-contrib/less-loader/issues/357
|
|
54
54
|
this.addDependency(_path.default.normalize(error.filename));
|
|
55
55
|
}
|
|
@@ -71,7 +71,7 @@ async function lessLoader(source) {
|
|
|
71
71
|
|
|
72
72
|
this.addDependency(_path.default.normalize(item));
|
|
73
73
|
});
|
|
74
|
-
let map = typeof result.map ===
|
|
74
|
+
let map = typeof result.map === "string" ? JSON.parse(result.map) : result.map;
|
|
75
75
|
|
|
76
76
|
if (map && useSourceMap) {
|
|
77
77
|
map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
|
package/dist/options.json
CHANGED
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
"webpackImporter": {
|
|
32
32
|
"description": "Enables/Disables default `webpack` importer (https://github.com/webpack-contrib/less-loader#webpackimporter).",
|
|
33
33
|
"type": "boolean"
|
|
34
|
+
},
|
|
35
|
+
"implementation": {
|
|
36
|
+
"description": "The implementation of the `Less` to be used (https://github.com/webpack-contrib/less-loader#implementation).",
|
|
37
|
+
"type": "object"
|
|
34
38
|
}
|
|
35
39
|
},
|
|
36
40
|
"additionalProperties": false
|
package/dist/utils.js
CHANGED
|
@@ -34,15 +34,15 @@ const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
|
34
34
|
|
|
35
35
|
function createWebpackLessPlugin(loaderContext) {
|
|
36
36
|
const resolve = loaderContext.getResolve({
|
|
37
|
-
conditionNames: [
|
|
38
|
-
mainFields: [
|
|
39
|
-
mainFiles: [
|
|
40
|
-
extensions: [
|
|
37
|
+
conditionNames: ["less", "style"],
|
|
38
|
+
mainFields: ["less", "style", "main", "..."],
|
|
39
|
+
mainFiles: ["index", "..."],
|
|
40
|
+
extensions: [".less", ".css"]
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
class WebpackFileManager extends _less.default.FileManager {
|
|
44
44
|
supports(filename) {
|
|
45
|
-
if (filename[0] ===
|
|
45
|
+
if (filename[0] === "/" || IS_NATIVE_WIN32_PATH.test(filename)) {
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -64,9 +64,9 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
64
64
|
|
|
65
65
|
async resolveFilename(filename, currentDirectory) {
|
|
66
66
|
// Less is giving us trailing slashes, but the context should have no trailing slash
|
|
67
|
-
const context = currentDirectory.replace(trailingSlash,
|
|
67
|
+
const context = currentDirectory.replace(trailingSlash, "");
|
|
68
68
|
const request = (0, _loaderUtils.urlToRequest)(filename, // eslint-disable-next-line no-undefined
|
|
69
|
-
filename.charAt(0) ===
|
|
69
|
+
filename.charAt(0) === "/" ? loaderContext.rootContext : undefined);
|
|
70
70
|
return this.resolveRequests(context, [...new Set([request, filename])]);
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -75,9 +75,7 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
75
75
|
return Promise.reject();
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
return resolve(context, possibleRequests[0]).then(result => {
|
|
79
|
-
return result;
|
|
80
|
-
}).catch(error => {
|
|
78
|
+
return resolve(context, possibleRequests[0]).then(result => result).catch(error => {
|
|
81
79
|
const [, ...tailPossibleRequests] = possibleRequests;
|
|
82
80
|
|
|
83
81
|
if (tailPossibleRequests.length === 0) {
|
|
@@ -94,13 +92,13 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
94
92
|
try {
|
|
95
93
|
if (IS_SPECIAL_MODULE_IMPORT.test(filename)) {
|
|
96
94
|
const error = new Error();
|
|
97
|
-
error.type =
|
|
95
|
+
error.type = "Next";
|
|
98
96
|
throw error;
|
|
99
97
|
}
|
|
100
98
|
|
|
101
99
|
result = await super.loadFile(filename, ...args);
|
|
102
100
|
} catch (error) {
|
|
103
|
-
if (error.type !==
|
|
101
|
+
if (error.type !== "File" && error.type !== "Next") {
|
|
104
102
|
return Promise.reject(error);
|
|
105
103
|
}
|
|
106
104
|
|
|
@@ -139,7 +137,7 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
139
137
|
|
|
140
138
|
|
|
141
139
|
function getLessOptions(loaderContext, loaderOptions) {
|
|
142
|
-
const options = (0, _full.klona)(typeof loaderOptions.lessOptions ===
|
|
140
|
+
const options = (0, _full.klona)(typeof loaderOptions.lessOptions === "function" ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {});
|
|
143
141
|
const lessOptions = {
|
|
144
142
|
plugins: [],
|
|
145
143
|
relativeUrls: true,
|
|
@@ -147,7 +145,7 @@ function getLessOptions(loaderContext, loaderOptions) {
|
|
|
147
145
|
filename: loaderContext.resourcePath,
|
|
148
146
|
...options
|
|
149
147
|
};
|
|
150
|
-
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter ===
|
|
148
|
+
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" ? loaderOptions.webpackImporter : true;
|
|
151
149
|
|
|
152
150
|
if (shouldUseWebpackImporter) {
|
|
153
151
|
lessOptions.plugins.unshift(createWebpackLessPlugin(loaderContext));
|
|
@@ -181,11 +179,9 @@ function normalizeSourceMap(map) {
|
|
|
181
179
|
|
|
182
180
|
delete newMap.file; // eslint-disable-next-line no-param-reassign
|
|
183
181
|
|
|
184
|
-
newMap.sourceRoot =
|
|
182
|
+
newMap.sourceRoot = ""; // `less` returns POSIX paths, that's why we need to transform them back to native paths.
|
|
185
183
|
// eslint-disable-next-line no-param-reassign
|
|
186
184
|
|
|
187
|
-
newMap.sources = newMap.sources.map(source =>
|
|
188
|
-
return _path.default.normalize(source);
|
|
189
|
-
});
|
|
185
|
+
newMap.sources = newMap.sources.map(source => _path.default.normalize(source));
|
|
190
186
|
return newMap;
|
|
191
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "less-loader",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "A Less loader for webpack. Compiles Less to CSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/less-loader",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dist"
|
|
39
39
|
],
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"less": "^3.5.0",
|
|
41
|
+
"less": "^3.5.0 || ^4.0.0",
|
|
42
42
|
"webpack": "^4.0.0 || ^5.0.0"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
@@ -47,32 +47,31 @@
|
|
|
47
47
|
"schema-utils": "^3.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/cli": "^7.
|
|
51
|
-
"@babel/core": "^7.
|
|
52
|
-
"@babel/preset-env": "^7.11
|
|
50
|
+
"@babel/cli": "^7.12.10",
|
|
51
|
+
"@babel/core": "^7.12.10",
|
|
52
|
+
"@babel/preset-env": "^7.12.11",
|
|
53
53
|
"@commitlint/cli": "^11.0.0",
|
|
54
54
|
"@commitlint/config-conventional": "^11.0.0",
|
|
55
55
|
"@webpack-contrib/defaults": "^6.3.0",
|
|
56
56
|
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
|
|
57
|
-
"babel-jest": "^26.
|
|
58
|
-
"cross-env": "^7.0.
|
|
57
|
+
"babel-jest": "^26.6.3",
|
|
58
|
+
"cross-env": "^7.0.3",
|
|
59
59
|
"del": "^6.0.0",
|
|
60
60
|
"del-cli": "^3.0.1",
|
|
61
|
-
"eslint": "^7.
|
|
62
|
-
"eslint-config-prettier": "^
|
|
61
|
+
"eslint": "^7.18.0",
|
|
62
|
+
"eslint-config-prettier": "^7.2.0",
|
|
63
63
|
"eslint-plugin-import": "^2.22.1",
|
|
64
|
-
"eslint-plugin-prettier": "^3.
|
|
65
|
-
"husky": "^4.3.
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"lint-staged": "^10.4.0",
|
|
64
|
+
"eslint-plugin-prettier": "^3.3.0",
|
|
65
|
+
"husky": "^4.3.8",
|
|
66
|
+
"jest": "^26.6.3",
|
|
67
|
+
"less": "^4.1.0",
|
|
68
|
+
"lint-staged": "^10.5.3",
|
|
70
69
|
"memfs": "^3.2.0",
|
|
71
70
|
"npm-run-all": "^4.1.5",
|
|
72
|
-
"prettier": "^2.1
|
|
73
|
-
"standard-version": "^9.
|
|
71
|
+
"prettier": "^2.2.1",
|
|
72
|
+
"standard-version": "^9.1.0",
|
|
74
73
|
"strip-ansi": "^6.0.0",
|
|
75
|
-
"webpack": "^
|
|
74
|
+
"webpack": "^5.16.0"
|
|
76
75
|
},
|
|
77
76
|
"keywords": [
|
|
78
77
|
"webpack",
|