less-loader 4.0.6 → 4.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/CHANGELOG.md +10 -0
- package/README.md +10 -10
- package/dist/createWebpackLessPlugin.js +31 -5
- package/package.json +12 -14
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
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
|
+
<a name="4.1.0"></a>
|
|
6
|
+
# [4.1.0](https://github.com/webpack-contrib/less-loader/compare/v4.0.6...v4.1.0) (2018-03-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **package:** support `less >= v3.0.0` ([#242](https://github.com/webpack-contrib/less-loader/issues/242)) ([d8c9d83](https://github.com/webpack-contrib/less-loader/commit/d8c9d83))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
5
15
|
<a name="4.0.6"></a>
|
|
6
16
|
## [4.0.6](https://github.com/webpack-contrib/less-loader/compare/v4.0.5...v4.0.6) (2018-02-27)
|
|
7
17
|
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
<p align="center">Compiles Less to CSS.</p>
|
|
22
22
|
|
|
23
|
-
Use the [css-loader](https://github.com/webpack-contrib/css-loader) or the [raw-loader](https://github.com/webpack-contrib/raw-loader) to turn it into a JS module and the [ExtractTextPlugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) to extract it into a separate file.
|
|
23
|
+
Use the [`css-loader`](https://github.com/webpack-contrib/css-loader) or the [`raw-loader`](https://github.com/webpack-contrib/raw-loader) to turn it into a JS module and the [ExtractTextPlugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) to extract it into a separate file.
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
<h2 align="center">Install</h2>
|
|
@@ -29,11 +29,11 @@ Use the [css-loader](https://github.com/webpack-contrib/css-loader) or the [raw-
|
|
|
29
29
|
npm install --save-dev less-loader less
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
The less-loader requires [less](https://github.com/less/less.js) as [`peerDependency`](https://docs.npmjs.com/files/package.json#peerdependencies). Thus you are able to control the versions accurately.
|
|
32
|
+
The `less-loader` requires [less](https://github.com/less/less.js) as [`peerDependency`](https://docs.npmjs.com/files/package.json#peerdependencies). Thus you are able to control the versions accurately.
|
|
33
33
|
|
|
34
34
|
<h2 align="center">Examples</h2>
|
|
35
35
|
|
|
36
|
-
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.
|
|
36
|
+
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.
|
|
37
37
|
|
|
38
38
|
```js
|
|
39
39
|
// webpack.config.js
|
|
@@ -54,7 +54,7 @@ module.exports = {
|
|
|
54
54
|
};
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
You can pass any Less specific options to the less-loader via [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:
|
|
57
|
+
You can pass any Less specific options to the `less-loader` via [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:
|
|
58
58
|
|
|
59
59
|
```js
|
|
60
60
|
// webpack.config.js
|
|
@@ -118,11 +118,11 @@ module.exports = {
|
|
|
118
118
|
|
|
119
119
|
### Imports
|
|
120
120
|
|
|
121
|
-
Starting with less-loader 4, you can now choose between Less' builtin resolver and webpack's resolver. By default, webpack's resolver is used.
|
|
121
|
+
Starting with `less-loader` 4, you can now choose between Less' builtin resolver and webpack's resolver. By default, webpack's resolver is used.
|
|
122
122
|
|
|
123
123
|
#### webpack resolver
|
|
124
124
|
|
|
125
|
-
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).
|
|
125
|
+
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).
|
|
126
126
|
|
|
127
127
|
```css
|
|
128
128
|
@import "~bootstrap/less/bootstrap";
|
|
@@ -152,7 +152,7 @@ module.exports = {
|
|
|
152
152
|
|
|
153
153
|
#### Less resolver
|
|
154
154
|
|
|
155
|
-
If you specify the `paths` option, the less-loader will not use webpack's resolver. Modules, that can't be resolved in the local folder, will be searched in the given `paths`. This is Less' default behavior. `paths` should be an array with absolute paths:
|
|
155
|
+
If you specify the `paths` option, the `less-loader` will not use webpack's resolver. Modules, that can't be resolved in the local folder, will be searched in the given `paths`. This is Less' default behavior. `paths` should be an array with absolute paths:
|
|
156
156
|
|
|
157
157
|
```js
|
|
158
158
|
// webpack.config.js
|
|
@@ -206,12 +206,12 @@ Bundling CSS with webpack has some nice advantages like referencing images and f
|
|
|
206
206
|
|
|
207
207
|
There are two possibilities to extract a style sheet from the bundle:
|
|
208
208
|
|
|
209
|
-
- [extract-loader](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
|
|
210
|
-
- [
|
|
209
|
+
- [`extract-loader`](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
|
|
210
|
+
- [`ExtractTextWebpackPlugin`](https://github.com/webpack-contrib/extract-text-webpack-plugin) (more complex, but works in all use-cases)
|
|
211
211
|
|
|
212
212
|
### Source maps
|
|
213
213
|
|
|
214
|
-
To enable CSS source maps, you'll need to pass the `sourceMap` option to the less-loader *and* the css-loader
|
|
214
|
+
To enable CSS source maps, you'll need to pass the `sourceMap` option to the `less-loader` *and* the `css-loader`. Your `webpack.config.js` should look like this:
|
|
215
215
|
|
|
216
216
|
```javascript
|
|
217
217
|
module.exports = {
|
|
@@ -8,6 +8,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
8
8
|
|
|
9
9
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
10
10
|
|
|
11
|
+
/* eslint-disable class-methods-use-this */
|
|
11
12
|
var less = require('less');
|
|
12
13
|
var loaderUtils = require('loader-utils');
|
|
13
14
|
var pify = require('pify');
|
|
@@ -15,6 +16,7 @@ var pify = require('pify');
|
|
|
15
16
|
var stringifyLoader = require.resolve('./stringifyLoader.js');
|
|
16
17
|
var trailingSlash = /[/\\]$/;
|
|
17
18
|
var isLessCompatible = /\.(le|c)ss$/;
|
|
19
|
+
|
|
18
20
|
// Less automatically adds a .less file extension if no extension was given.
|
|
19
21
|
// This is problematic if there is a module request like @import "~some-module";
|
|
20
22
|
// because in this case Less will call our file manager with `~some-module.less`.
|
|
@@ -23,6 +25,11 @@ var isLessCompatible = /\.(le|c)ss$/;
|
|
|
23
25
|
// However, we must not match something like @import "~some-module/file.less";
|
|
24
26
|
var matchMalformedModuleFilename = /(~[^/\\]+)\.less$/;
|
|
25
27
|
|
|
28
|
+
// This somewhat changed in Less 3.x. Now the file name comes without the
|
|
29
|
+
// automatically added extension whereas the extension is passed in as `options.ext`.
|
|
30
|
+
// So, if the file name matches this regexp, we simply ignore the proposed extension.
|
|
31
|
+
var isModuleName = /^~[^/\\]+$/;
|
|
32
|
+
|
|
26
33
|
/**
|
|
27
34
|
* Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext.
|
|
28
35
|
*
|
|
@@ -48,16 +55,35 @@ function createWebpackLessPlugin(loaderContext) {
|
|
|
48
55
|
|
|
49
56
|
_createClass(WebpackFileManager, [{
|
|
50
57
|
key: 'supports',
|
|
51
|
-
value: function supports()
|
|
52
|
-
// eslint-disable-line class-methods-use-this
|
|
58
|
+
value: function supports() {
|
|
53
59
|
// Our WebpackFileManager handles all the files
|
|
54
60
|
return true;
|
|
55
61
|
}
|
|
62
|
+
|
|
63
|
+
// Sync resolving is used at least by the `data-uri` function.
|
|
64
|
+
// This file manager doesn't know how to do it, so let's delegate it
|
|
65
|
+
// to the default file manager of Less.
|
|
66
|
+
// We could probably use loaderContext.resolveSync, but it's deprecated,
|
|
67
|
+
// see https://webpack.js.org/api/loaders/#this-resolvesync
|
|
68
|
+
|
|
69
|
+
}, {
|
|
70
|
+
key: 'supportsSync',
|
|
71
|
+
value: function supportsSync() {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
56
74
|
}, {
|
|
57
75
|
key: 'loadFile',
|
|
58
|
-
value: function loadFile(filename, currentDirectory
|
|
59
|
-
|
|
60
|
-
|
|
76
|
+
value: function loadFile(filename, currentDirectory, options) {
|
|
77
|
+
var url = void 0;
|
|
78
|
+
if (less.version[0] >= 3) {
|
|
79
|
+
if (options.ext && !isModuleName.test(filename)) {
|
|
80
|
+
url = this.tryAppendExtension(filename, options.ext);
|
|
81
|
+
} else {
|
|
82
|
+
url = filename;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
url = filename.replace(matchMalformedModuleFilename, '$1');
|
|
86
|
+
}
|
|
61
87
|
var moduleRequest = loaderUtils.urlToRequest(url, url.charAt(0) === '/' ? '' : null);
|
|
62
88
|
// Less is giving us trailing slashes, but the context should have no trailing slash
|
|
63
89
|
var context = currentDirectory.replace(trailingSlash, '');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "less-loader",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"author": "Johannes Ewald @jhnns",
|
|
5
5
|
"description": "Less loader for webpack. Compiles Less to CSS.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,27 +12,26 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
|
+
"start": "npm run build -- -w",
|
|
16
|
+
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
|
|
17
|
+
"clean": "del-cli dist",
|
|
15
18
|
"create-spec": "babel-node test/helpers/createSpec.js",
|
|
19
|
+
"lint": "eslint --cache src test",
|
|
16
20
|
"pretest": "npm run create-spec",
|
|
17
21
|
"test": "jest",
|
|
18
22
|
"posttest": "npm run lint",
|
|
19
|
-
"travis:test": "npm run test -- --runInBand",
|
|
20
|
-
"appveyor:test": "npm run test",
|
|
21
|
-
"lint": "eslint --cache src test",
|
|
22
|
-
"webpack-defaults": "webpack-defaults",
|
|
23
|
-
"start": "npm run build -- -w",
|
|
24
|
-
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
|
|
25
23
|
"lint-staged": "lint-staged",
|
|
26
24
|
"prebuild": "npm run clean",
|
|
27
25
|
"prepare": "npm run build",
|
|
28
26
|
"release": "standard-version",
|
|
29
27
|
"security": "nsp check",
|
|
30
|
-
"test:watch": "jest --watch",
|
|
31
28
|
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
|
|
29
|
+
"travis:lint": "npm run lint && npm run security",
|
|
30
|
+
"travis:test": "npm run test -- --runInBand",
|
|
32
31
|
"pretravis:coverage": "npm run pretest",
|
|
33
32
|
"travis:coverage": "npm run test:coverage -- --runInBand",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
33
|
+
"appveyor:test": "npm run test",
|
|
34
|
+
"defaults": "webpack-defaults"
|
|
36
35
|
},
|
|
37
36
|
"dependencies": {
|
|
38
37
|
"clone": "^2.1.1",
|
|
@@ -40,7 +39,7 @@
|
|
|
40
39
|
"pify": "^3.0.0"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
43
|
-
"less": "^2.3.1",
|
|
42
|
+
"less": "^2.3.1 || ^3.0.0",
|
|
44
43
|
"webpack": "^2.0.0 || ^3.0.0 || ^4.0.0"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
@@ -56,13 +55,12 @@
|
|
|
56
55
|
"eslint-plugin-import": "^2.2.0",
|
|
57
56
|
"inspect-loader": "^1.0.0",
|
|
58
57
|
"jest": "^21.2.1",
|
|
59
|
-
"less": "^
|
|
58
|
+
"less": "^3.0.1",
|
|
60
59
|
"lint-staged": "^3.4.0",
|
|
61
|
-
"nodemon": "^1.11.0",
|
|
62
60
|
"nsp": "^2.6.3",
|
|
63
61
|
"pre-commit": "^1.2.2",
|
|
64
62
|
"standard-version": "^4.0.0",
|
|
65
|
-
"webpack": "
|
|
63
|
+
"webpack": "^3.0.0",
|
|
66
64
|
"webpack-defaults": "^1.6.0"
|
|
67
65
|
},
|
|
68
66
|
"repository": "https://github.com/webpack-contrib/less-loader.git",
|