less-loader 6.1.3 → 7.0.2
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 +34 -0
- package/README.md +37 -95
- package/dist/LessError.js +4 -4
- package/dist/index.js +43 -26
- package/dist/options.json +5 -16
- package/dist/utils.js +41 -36
- package/package.json +21 -20
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,40 @@
|
|
|
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.0.2](https://github.com/webpack-contrib/less-loader/compare/v7.0.1...v7.0.2) (2020-10-09)
|
|
6
|
+
|
|
7
|
+
### Chore
|
|
8
|
+
|
|
9
|
+
* update `schema-utils`
|
|
10
|
+
|
|
11
|
+
### [7.0.1](https://github.com/webpack-contrib/less-loader/compare/v7.0.0...v7.0.1) (2020-09-03)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* normalize `sources` in source maps ([877d99a](https://github.com/webpack-contrib/less-loader/commit/877d99a380deac92e07c41429a9b0c5f0bba2710))
|
|
17
|
+
|
|
18
|
+
## [7.0.0](https://github.com/webpack-contrib/less-loader/compare/v6.2.0...v7.0.0) (2020-08-25)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### ⚠ BREAKING CHANGES
|
|
22
|
+
|
|
23
|
+
* move `less` to `peerDependencies`, the `implementation` option was removed
|
|
24
|
+
* `prependData` and `appendData` option were removed in favor the `additionaldata` option
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* added `webpackImporter` option ([#377](https://github.com/webpack-contrib/less-loader/issues/377)) ([12dca5b](https://github.com/webpack-contrib/less-loader/commit/12dca5bb573740472cff8176b7aade184c773ebc))
|
|
29
|
+
* added loader context in less plugins ([#378](https://github.com/webpack-contrib/less-loader/issues/378)) ([7b7fc5e](https://github.com/webpack-contrib/less-loader/commit/7b7fc5e841a2c7c587a980648056ed4762014e9d))
|
|
30
|
+
* added `additionaldata` option ([#374](https://github.com/webpack-contrib/less-loader/issues/374)) ([2785803](https://github.com/webpack-contrib/less-loader/commit/27858037a2e307fdf437604300f14c8233df4568))
|
|
31
|
+
|
|
32
|
+
## [6.2.0](https://github.com/webpack-contrib/less-loader/compare/v6.1.3...v6.2.0) (2020-07-03)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Features
|
|
36
|
+
|
|
37
|
+
* support condition names from `package.json` ([#369](https://github.com/webpack-contrib/less-loader/issues/369)) ([671395d](https://github.com/webpack-contrib/less-loader/commit/671395d6a82425ba4408d1329d8cbfa07dfd9153))
|
|
38
|
+
|
|
5
39
|
### [6.1.3](https://github.com/webpack-contrib/less-loader/compare/v6.1.2...v6.1.3) (2020-06-29)
|
|
6
40
|
|
|
7
41
|
|
package/README.md
CHANGED
|
@@ -18,10 +18,10 @@ A Less loader for webpack. Compiles Less to CSS.
|
|
|
18
18
|
|
|
19
19
|
## Getting Started
|
|
20
20
|
|
|
21
|
-
To begin, you'll need to install `less-loader`:
|
|
21
|
+
To begin, you'll need to install `less` and `less-loader`:
|
|
22
22
|
|
|
23
23
|
```console
|
|
24
|
-
$ npm install less-loader --save-dev
|
|
24
|
+
$ npm install less less-loader --save-dev
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
Then add the loader to your `webpack` config. For example:
|
|
@@ -45,13 +45,12 @@ And run `webpack` via your preferred method.
|
|
|
45
45
|
|
|
46
46
|
## Options
|
|
47
47
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
| **[`implementation`](#implementation)** | `{Object}` | `less` | Setup Less implementation to use. |
|
|
48
|
+
| Name | Type | Default | Description |
|
|
49
|
+
| :---------------------------------------: | :------------------: | :----------------------: | :----------------------------------------------------- |
|
|
50
|
+
| **[`lessOptions`](#lessoptions)** | `{Object\|Function}` | `{ relativeUrls: true }` | Options for Less. |
|
|
51
|
+
| **[`additionalData`](#additionalData)** | `{String\|Function}` | `undefined` | Prepends/Appends `Less` code to the actual entry file. |
|
|
52
|
+
| **[`sourceMap`](#sourcemap)** | `{Boolean}` | `compiler.devtool` | Enables/Disables generation of source maps. |
|
|
53
|
+
| **[`webpackImporter`](#webpackimporter)** | `{Boolean}` | `true` | Enables/Disables the default Webpack importer. |
|
|
55
54
|
|
|
56
55
|
### `lessOptions`
|
|
57
56
|
|
|
@@ -134,12 +133,13 @@ module.exports = {
|
|
|
134
133
|
};
|
|
135
134
|
```
|
|
136
135
|
|
|
137
|
-
### `
|
|
136
|
+
### `additionalData`
|
|
138
137
|
|
|
139
138
|
Type: `String|Function`
|
|
140
139
|
Default: `undefined`
|
|
141
140
|
|
|
142
141
|
Prepends `Less` code before the actual entry file.
|
|
142
|
+
In this case, the `less-loader` will not override the source but just **prepend** the entry's content.
|
|
143
143
|
|
|
144
144
|
This is especially useful when some of your Less variables depend on the environment:
|
|
145
145
|
|
|
@@ -159,7 +159,7 @@ module.exports = {
|
|
|
159
159
|
{
|
|
160
160
|
loader: 'less-loader',
|
|
161
161
|
options: {
|
|
162
|
-
|
|
162
|
+
additionalData: `@env: ${process.env.NODE_ENV};`,
|
|
163
163
|
},
|
|
164
164
|
},
|
|
165
165
|
],
|
|
@@ -183,85 +183,16 @@ module.exports = {
|
|
|
183
183
|
{
|
|
184
184
|
loader: 'less-loader',
|
|
185
185
|
options: {
|
|
186
|
-
|
|
186
|
+
additionalData: (content, loaderContext) => {
|
|
187
187
|
// More information about available properties https://webpack.js.org/api/loaders/
|
|
188
188
|
const { resourcePath, rootContext } = loaderContext;
|
|
189
189
|
const relativePath = path.relative(rootContext, resourcePath);
|
|
190
190
|
|
|
191
191
|
if (relativePath === 'styles/foo.less') {
|
|
192
|
-
return '@value: 100px;';
|
|
192
|
+
return '@value: 100px;' + content;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
return '@value: 200px;';
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### `appendData`
|
|
207
|
-
|
|
208
|
-
Type: `String|Function`
|
|
209
|
-
Default: `undefined`
|
|
210
|
-
|
|
211
|
-
AppendData `Less` code after the actual entry file.
|
|
212
|
-
|
|
213
|
-
This can be useful when you need to rewrite some of your Less variables.:
|
|
214
|
-
|
|
215
|
-
> ℹ 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.
|
|
216
|
-
|
|
217
|
-
#### `String`
|
|
218
|
-
|
|
219
|
-
```js
|
|
220
|
-
module.exports = {
|
|
221
|
-
module: {
|
|
222
|
-
rules: [
|
|
223
|
-
{
|
|
224
|
-
test: /\.less$/,
|
|
225
|
-
use: [
|
|
226
|
-
'style-loader',
|
|
227
|
-
'css-loader',
|
|
228
|
-
{
|
|
229
|
-
loader: 'less-loader',
|
|
230
|
-
options: {
|
|
231
|
-
appendData: `@env: ${process.env.NODE_ENV};`,
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
],
|
|
235
|
-
},
|
|
236
|
-
],
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
#### `Function`
|
|
242
|
-
|
|
243
|
-
```js
|
|
244
|
-
module.exports = {
|
|
245
|
-
module: {
|
|
246
|
-
rules: [
|
|
247
|
-
{
|
|
248
|
-
test: /\.less$/,
|
|
249
|
-
use: [
|
|
250
|
-
'style-loader',
|
|
251
|
-
'css-loader',
|
|
252
|
-
{
|
|
253
|
-
loader: 'less-loader',
|
|
254
|
-
options: {
|
|
255
|
-
appendData: (loaderContext) => {
|
|
256
|
-
// More information about available properties https://webpack.js.org/api/loaders/
|
|
257
|
-
const { resourcePath, rootContext } = loaderContext;
|
|
258
|
-
const relativePath = path.relative(rootContext, resourcePath);
|
|
259
|
-
|
|
260
|
-
if (relativePath === 'styles/foo.less') {
|
|
261
|
-
return '@value: 100px;';
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return '@value: 200px;';
|
|
195
|
+
return '@value: 200px;' + content;
|
|
265
196
|
},
|
|
266
197
|
},
|
|
267
198
|
},
|
|
@@ -308,32 +239,30 @@ module.exports = {
|
|
|
308
239
|
};
|
|
309
240
|
```
|
|
310
241
|
|
|
311
|
-
### `
|
|
242
|
+
### `webpackImporter`
|
|
312
243
|
|
|
313
|
-
Type: `
|
|
314
|
-
Default: `
|
|
244
|
+
Type: `Boolean`
|
|
245
|
+
Default: `true`
|
|
315
246
|
|
|
316
|
-
|
|
247
|
+
Enables/Disables the default Webpack importer.
|
|
317
248
|
|
|
318
|
-
|
|
319
|
-
The `implementation` options either accepts `less` as a module.
|
|
320
|
-
This is useful if you want to use Less with a smaller version. Do not forget that then you must install your own version of Less.
|
|
249
|
+
This can improve performance in some cases. Use it with caution because aliases and `@import` at-rules starting with `~` will not work.
|
|
321
250
|
|
|
322
|
-
|
|
251
|
+
**webpack.config.js**
|
|
323
252
|
|
|
324
253
|
```js
|
|
325
254
|
module.exports = {
|
|
326
255
|
module: {
|
|
327
256
|
rules: [
|
|
328
257
|
{
|
|
329
|
-
test: /\.less
|
|
258
|
+
test: /\.less$/i,
|
|
330
259
|
use: [
|
|
331
260
|
'style-loader',
|
|
332
261
|
'css-loader',
|
|
333
262
|
{
|
|
334
263
|
loader: 'less-loader',
|
|
335
264
|
options: {
|
|
336
|
-
|
|
265
|
+
webpackImporter: false,
|
|
337
266
|
},
|
|
338
267
|
},
|
|
339
268
|
],
|
|
@@ -489,8 +418,7 @@ module.exports = {
|
|
|
489
418
|
|
|
490
419
|
### Plugins
|
|
491
420
|
|
|
492
|
-
In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the
|
|
493
|
-
`plugins` option like this:
|
|
421
|
+
In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the `plugins` option like this:
|
|
494
422
|
|
|
495
423
|
```js
|
|
496
424
|
// webpack.config.js
|
|
@@ -512,6 +440,20 @@ module.exports = {
|
|
|
512
440
|
};
|
|
513
441
|
```
|
|
514
442
|
|
|
443
|
+
> ℹ️ Access to the [loader context](https://webpack.js.org/api/loaders/#the-loader-context) inside the custom plugin can be done using the `less.webpackLoaderContext` property.
|
|
444
|
+
|
|
445
|
+
```js
|
|
446
|
+
module.exports = {
|
|
447
|
+
install: function (less, pluginManager, functions) {
|
|
448
|
+
functions.add('pi', function () {
|
|
449
|
+
// Loader context is available in `less.webpackLoaderContext`
|
|
450
|
+
|
|
451
|
+
return Math.PI;
|
|
452
|
+
});
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
```
|
|
456
|
+
|
|
515
457
|
### Extracting style sheets
|
|
516
458
|
|
|
517
459
|
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.
|
package/dist/LessError.js
CHANGED
|
@@ -16,13 +16,13 @@ class LessError extends Error {
|
|
|
16
16
|
this.hideStack = true;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
static getFileExcerptIfPossible(
|
|
20
|
-
if (typeof
|
|
19
|
+
static getFileExcerptIfPossible(lessError) {
|
|
20
|
+
if (typeof lessError.extract === 'undefined') {
|
|
21
21
|
return [];
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const excerpt =
|
|
25
|
-
const column = Math.max(
|
|
24
|
+
const excerpt = lessError.extract.slice(0, 2);
|
|
25
|
+
const column = Math.max(lessError.column - 1, 0);
|
|
26
26
|
|
|
27
27
|
if (typeof excerpt[0] === 'undefined') {
|
|
28
28
|
excerpt.shift();
|
package/dist/index.js
CHANGED
|
@@ -7,9 +7,11 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
|
|
10
|
+
var _less = _interopRequireDefault(require("less"));
|
|
11
|
+
|
|
10
12
|
var _loaderUtils = require("loader-utils");
|
|
11
13
|
|
|
12
|
-
var _schemaUtils =
|
|
14
|
+
var _schemaUtils = require("schema-utils");
|
|
13
15
|
|
|
14
16
|
var _options = _interopRequireDefault(require("./options.json"));
|
|
15
17
|
|
|
@@ -19,48 +21,63 @@ var _LessError = _interopRequireDefault(require("./LessError"));
|
|
|
19
21
|
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
|
-
function lessLoader(source) {
|
|
24
|
+
async function lessLoader(source) {
|
|
23
25
|
const options = (0, _loaderUtils.getOptions)(this);
|
|
24
|
-
(0, _schemaUtils.
|
|
26
|
+
(0, _schemaUtils.validate)(_options.default, options, {
|
|
25
27
|
name: 'Less Loader',
|
|
26
28
|
baseDataPath: 'options'
|
|
27
29
|
});
|
|
28
30
|
const callback = this.async();
|
|
29
31
|
const lessOptions = (0, _utils.getLessOptions)(this, options);
|
|
30
|
-
|
|
32
|
+
const useSourceMap = typeof options.sourceMap === 'boolean' ? options.sourceMap : this.sourceMap;
|
|
31
33
|
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
+
if (useSourceMap) {
|
|
35
|
+
lessOptions.sourceMap = {
|
|
36
|
+
outputSourceFiles: true
|
|
37
|
+
};
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
data = typeof options.appendData === 'function' ? `${data}\n${options.appendData(this)}` : `${data}\n${options.appendData}`;
|
|
38
|
-
}
|
|
40
|
+
let data = source;
|
|
39
41
|
|
|
40
|
-
(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
imports
|
|
44
|
-
}) => {
|
|
45
|
-
imports.forEach(item => {
|
|
46
|
-
if ((0, _utils.isUnsupportedUrl)(item)) {
|
|
47
|
-
return;
|
|
48
|
-
} // `less` return forward slashes on windows when `webpack` resolver return an absolute windows path in `WebpackFileManager`
|
|
49
|
-
// Ref: https://github.com/webpack-contrib/less-loader/issues/357
|
|
42
|
+
if (typeof options.additionalData !== 'undefined') {
|
|
43
|
+
data = typeof options.additionalData === 'function' ? `${options.additionalData(data, this)}` : `${options.additionalData}\n${data}`;
|
|
44
|
+
}
|
|
50
45
|
|
|
46
|
+
let result;
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (lessError.filename) {
|
|
48
|
+
try {
|
|
49
|
+
result = await _less.default.render(data, lessOptions);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error.filename) {
|
|
57
52
|
// `less` return forward slashes on windows when `webpack` resolver return an absolute windows path in `WebpackFileManager`
|
|
58
53
|
// Ref: https://github.com/webpack-contrib/less-loader/issues/357
|
|
59
|
-
this.addDependency(_path.default.normalize(
|
|
54
|
+
this.addDependency(_path.default.normalize(error.filename));
|
|
60
55
|
}
|
|
61
56
|
|
|
62
|
-
callback(new _LessError.default(
|
|
57
|
+
callback(new _LessError.default(error));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const {
|
|
62
|
+
css,
|
|
63
|
+
imports
|
|
64
|
+
} = result;
|
|
65
|
+
imports.forEach(item => {
|
|
66
|
+
if ((0, _utils.isUnsupportedUrl)(item)) {
|
|
67
|
+
return;
|
|
68
|
+
} // `less` return 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
|
+
|
|
71
|
+
|
|
72
|
+
this.addDependency(_path.default.normalize(item));
|
|
63
73
|
});
|
|
74
|
+
let map = typeof result.map === 'string' ? JSON.parse(result.map) : result.map;
|
|
75
|
+
|
|
76
|
+
if (map && useSourceMap) {
|
|
77
|
+
map = (0, _utils.normalizeSourceMap)(map, this.rootContext);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
callback(null, css, map);
|
|
64
81
|
}
|
|
65
82
|
|
|
66
83
|
var _default = lessLoader;
|
package/dist/options.json
CHANGED
|
@@ -13,19 +13,8 @@
|
|
|
13
13
|
}
|
|
14
14
|
]
|
|
15
15
|
},
|
|
16
|
-
"
|
|
17
|
-
"description": "Prepends `Less` code
|
|
18
|
-
"anyOf": [
|
|
19
|
-
{
|
|
20
|
-
"type": "string"
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"instanceof": "Function"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
"appendData": {
|
|
28
|
-
"description": "Add `Less` code after the actual entry file (https://github.com/webpack-contrib/less-loader#postponeddata).",
|
|
16
|
+
"additionalData": {
|
|
17
|
+
"description": "Prepends/Appends `Less` code to the actual entry file (https://github.com/webpack-contrib/less-loader#additionalData).",
|
|
29
18
|
"anyOf": [
|
|
30
19
|
{
|
|
31
20
|
"type": "string"
|
|
@@ -39,9 +28,9 @@
|
|
|
39
28
|
"description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/less-loader#sourcemap).",
|
|
40
29
|
"type": "boolean"
|
|
41
30
|
},
|
|
42
|
-
"
|
|
43
|
-
"description": "
|
|
44
|
-
"type": "
|
|
31
|
+
"webpackImporter": {
|
|
32
|
+
"description": "Enables/Disables default `webpack` importer (https://github.com/webpack-contrib/less-loader#webpackimporter).",
|
|
33
|
+
"type": "boolean"
|
|
45
34
|
}
|
|
46
35
|
},
|
|
47
36
|
"additionalProperties": false
|
package/dist/utils.js
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getLessImplementation = getLessImplementation;
|
|
7
6
|
exports.getLessOptions = getLessOptions;
|
|
8
7
|
exports.isUnsupportedUrl = isUnsupportedUrl;
|
|
8
|
+
exports.normalizeSourceMap = normalizeSourceMap;
|
|
9
9
|
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
|
|
12
12
|
var _less = _interopRequireDefault(require("less"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _full = require("klona/full");
|
|
15
15
|
|
|
16
16
|
var _loaderUtils = require("loader-utils");
|
|
17
17
|
|
|
@@ -22,9 +22,9 @@ const trailingSlash = /[/\\]$/; // This somewhat changed in Less 3.x. Now the fi
|
|
|
22
22
|
// automatically added extension whereas the extension is passed in as `options.ext`.
|
|
23
23
|
// So, if the file name matches this regexp, we simply ignore the proposed extension.
|
|
24
24
|
|
|
25
|
-
const
|
|
25
|
+
const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/; // `[drive_letter]:\` + `\\[server]\[sharename]\`
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
28
28
|
/**
|
|
29
29
|
* Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext.
|
|
30
30
|
*
|
|
@@ -34,6 +34,7 @@ const isNativeWin32Path = /^[a-zA-Z]:[/\\]|^\\\\/i;
|
|
|
34
34
|
|
|
35
35
|
function createWebpackLessPlugin(loaderContext) {
|
|
36
36
|
const resolve = loaderContext.getResolve({
|
|
37
|
+
conditionNames: ['less', 'style'],
|
|
37
38
|
mainFields: ['less', 'style', 'main', '...'],
|
|
38
39
|
mainFiles: ['index', '...'],
|
|
39
40
|
extensions: ['.less', '.css']
|
|
@@ -41,7 +42,7 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
41
42
|
|
|
42
43
|
class WebpackFileManager extends _less.default.FileManager {
|
|
43
44
|
supports(filename) {
|
|
44
|
-
if (filename[0] === '/' ||
|
|
45
|
+
if (filename[0] === '/' || IS_NATIVE_WIN32_PATH.test(filename)) {
|
|
45
46
|
return true;
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -61,20 +62,12 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
61
62
|
return false;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return this.tryAppendExtension(filename, options.ext);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return filename;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async resolveFilename(filename, currentDirectory, options) {
|
|
73
|
-
const url = this.getUrl(filename, options);
|
|
74
|
-
const request = (0, _loaderUtils.urlToRequest)(url, url.charAt(0) === '/' ? loaderContext.rootContext : null); // Less is giving us trailing slashes, but the context should have no trailing slash
|
|
75
|
-
|
|
65
|
+
async resolveFilename(filename, currentDirectory) {
|
|
66
|
+
// Less is giving us trailing slashes, but the context should have no trailing slash
|
|
76
67
|
const context = currentDirectory.replace(trailingSlash, '');
|
|
77
|
-
|
|
68
|
+
const request = (0, _loaderUtils.urlToRequest)(filename, // eslint-disable-next-line no-undefined
|
|
69
|
+
filename.charAt(0) === '/' ? loaderContext.rootContext : undefined);
|
|
70
|
+
return this.resolveRequests(context, [...new Set([request, filename])]);
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
resolveRequests(context, possibleRequests) {
|
|
@@ -99,7 +92,7 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
99
92
|
let result;
|
|
100
93
|
|
|
101
94
|
try {
|
|
102
|
-
if (
|
|
95
|
+
if (IS_SPECIAL_MODULE_IMPORT.test(filename)) {
|
|
103
96
|
const error = new Error();
|
|
104
97
|
error.type = 'Next';
|
|
105
98
|
throw error;
|
|
@@ -146,7 +139,7 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
146
139
|
|
|
147
140
|
|
|
148
141
|
function getLessOptions(loaderContext, loaderOptions) {
|
|
149
|
-
const options = (0,
|
|
142
|
+
const options = (0, _full.klona)(typeof loaderOptions.lessOptions === 'function' ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {});
|
|
150
143
|
const lessOptions = {
|
|
151
144
|
plugins: [],
|
|
152
145
|
relativeUrls: true,
|
|
@@ -154,33 +147,45 @@ function getLessOptions(loaderContext, loaderOptions) {
|
|
|
154
147
|
filename: loaderContext.resourcePath,
|
|
155
148
|
...options
|
|
156
149
|
};
|
|
157
|
-
|
|
158
|
-
const useSourceMap = typeof loaderOptions.sourceMap === 'boolean' ? loaderOptions.sourceMap : loaderContext.sourceMap;
|
|
150
|
+
const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === 'boolean' ? loaderOptions.webpackImporter : true;
|
|
159
151
|
|
|
160
|
-
if (
|
|
161
|
-
lessOptions.
|
|
162
|
-
outputSourceFiles: true
|
|
163
|
-
};
|
|
152
|
+
if (shouldUseWebpackImporter) {
|
|
153
|
+
lessOptions.plugins.unshift(createWebpackLessPlugin(loaderContext));
|
|
164
154
|
}
|
|
165
155
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return implementation;
|
|
172
|
-
}
|
|
156
|
+
lessOptions.plugins.unshift({
|
|
157
|
+
install(lessProcessor) {
|
|
158
|
+
// eslint-disable-next-line no-param-reassign
|
|
159
|
+
lessProcessor.webpackLoaderContext = loaderContext;
|
|
160
|
+
}
|
|
173
161
|
|
|
174
|
-
|
|
162
|
+
});
|
|
163
|
+
return lessOptions;
|
|
175
164
|
}
|
|
176
165
|
|
|
177
166
|
function isUnsupportedUrl(url) {
|
|
178
|
-
// Is Windows
|
|
179
|
-
if (
|
|
167
|
+
// Is Windows path
|
|
168
|
+
if (IS_NATIVE_WIN32_PATH.test(url)) {
|
|
180
169
|
return false;
|
|
181
170
|
} // Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
|
|
182
171
|
// Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
|
|
183
172
|
|
|
184
173
|
|
|
185
174
|
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function normalizeSourceMap(map) {
|
|
178
|
+
const newMap = map; // map.file is an optional property that provides the output filename.
|
|
179
|
+
// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
|
|
180
|
+
// eslint-disable-next-line no-param-reassign
|
|
181
|
+
|
|
182
|
+
delete newMap.file; // eslint-disable-next-line no-param-reassign
|
|
183
|
+
|
|
184
|
+
newMap.sourceRoot = ''; // `less` returns POSIX paths, that's why we need to transform them back to native paths.
|
|
185
|
+
// eslint-disable-next-line no-param-reassign
|
|
186
|
+
|
|
187
|
+
newMap.sources = newMap.sources.map(source => {
|
|
188
|
+
return _path.default.normalize(source);
|
|
189
|
+
});
|
|
190
|
+
return newMap;
|
|
186
191
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "less-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.2",
|
|
4
4
|
"description": "A Less loader for webpack. Compiles Less to CSS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "webpack-contrib/less-loader",
|
|
@@ -38,40 +38,41 @@
|
|
|
38
38
|
"dist"
|
|
39
39
|
],
|
|
40
40
|
"peerDependencies": {
|
|
41
|
+
"less": "^3.5.0",
|
|
41
42
|
"webpack": "^4.0.0 || ^5.0.0"
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"
|
|
45
|
-
"less": "^3.11.3",
|
|
45
|
+
"klona": "^2.0.4",
|
|
46
46
|
"loader-utils": "^2.0.0",
|
|
47
|
-
"schema-utils": "^
|
|
47
|
+
"schema-utils": "^3.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/cli": "^7.
|
|
51
|
-
"@babel/core": "^7.
|
|
52
|
-
"@babel/preset-env": "^7.
|
|
53
|
-
"@commitlint/cli": "^
|
|
54
|
-
"@commitlint/config-conventional": "^
|
|
50
|
+
"@babel/cli": "^7.11.6",
|
|
51
|
+
"@babel/core": "^7.11.6",
|
|
52
|
+
"@babel/preset-env": "^7.11.5",
|
|
53
|
+
"@commitlint/cli": "^11.0.0",
|
|
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.
|
|
57
|
+
"babel-jest": "^26.5.2",
|
|
58
58
|
"cross-env": "^7.0.2",
|
|
59
|
-
"del": "^
|
|
59
|
+
"del": "^6.0.0",
|
|
60
60
|
"del-cli": "^3.0.1",
|
|
61
|
-
"eslint": "^7.
|
|
62
|
-
"eslint-config-prettier": "^6.
|
|
63
|
-
"eslint-plugin-import": "^2.
|
|
61
|
+
"eslint": "^7.10.0",
|
|
62
|
+
"eslint-config-prettier": "^6.12.0",
|
|
63
|
+
"eslint-plugin-import": "^2.22.1",
|
|
64
64
|
"eslint-plugin-prettier": "^3.1.4",
|
|
65
|
-
"husky": "^4.
|
|
65
|
+
"husky": "^4.3.0",
|
|
66
66
|
"inspect-loader": "^1.0.0",
|
|
67
|
-
"jest": "^26.
|
|
68
|
-
"
|
|
67
|
+
"jest": "^26.5.2",
|
|
68
|
+
"less": "^3.12.2",
|
|
69
|
+
"lint-staged": "^10.4.0",
|
|
69
70
|
"memfs": "^3.2.0",
|
|
70
71
|
"npm-run-all": "^4.1.5",
|
|
71
|
-
"prettier": "^2.
|
|
72
|
-
"standard-version": "^
|
|
72
|
+
"prettier": "^2.1.2",
|
|
73
|
+
"standard-version": "^9.0.0",
|
|
73
74
|
"strip-ansi": "^6.0.0",
|
|
74
|
-
"webpack": "^4.
|
|
75
|
+
"webpack": "^4.44.2"
|
|
75
76
|
},
|
|
76
77
|
"keywords": [
|
|
77
78
|
"webpack",
|