less-loader 4.0.4 → 5.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/CHANGELOG.md CHANGED
@@ -2,6 +2,61 @@
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="5.0.0"></a>
6
+ # [5.0.0](https://github.com/webpack-contrib/less-loader/compare/v4.1.0...v5.0.0) (2019-04-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * webpack watching does not recover after broken less is fixed ([#289](https://github.com/webpack-contrib/less-loader/issues/289)) ([f41d12e](https://github.com/webpack-contrib/less-loader/commit/f41d12e))
12
+
13
+
14
+ ### Chores
15
+
16
+ * remove old bits mentioning webpack < 4 and node < 6 ([#286](https://github.com/webpack-contrib/less-loader/issues/286)) ([012eb8f](https://github.com/webpack-contrib/less-loader/commit/012eb8f))
17
+
18
+
19
+ ### Code Refactoring
20
+
21
+ * remove deprecated compress option ([#283](https://github.com/webpack-contrib/less-loader/issues/283)) ([3d6e9e9](https://github.com/webpack-contrib/less-loader/commit/3d6e9e9))
22
+
23
+
24
+ ### BREAKING CHANGES
25
+
26
+ * remove deprecated compress option.
27
+ * drop support for node < 6.9 and webpack < 4
28
+
29
+
30
+
31
+ <a name="4.1.0"></a>
32
+ # [4.1.0](https://github.com/webpack-contrib/less-loader/compare/v4.0.6...v4.1.0) (2018-03-09)
33
+
34
+
35
+ ### Features
36
+
37
+ * **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))
38
+
39
+
40
+
41
+ <a name="4.0.6"></a>
42
+ ## [4.0.6](https://github.com/webpack-contrib/less-loader/compare/v4.0.5...v4.0.6) (2018-02-27)
43
+
44
+
45
+ ### Bug Fixes
46
+
47
+ * **package:** add `webpack >= v4.0.0` (`peerDependencies`) ([#245](https://github.com/webpack-contrib/less-loader/issues/245)) ([011cc73](https://github.com/webpack-contrib/less-loader/commit/011cc73))
48
+
49
+
50
+
51
+ <a name="4.0.5"></a>
52
+ ## [4.0.5](https://github.com/webpack-contrib/less-loader/compare/v4.0.4...v4.0.5) (2017-07-10)
53
+
54
+
55
+ ### Chore
56
+
57
+ * support `webpack@3` ([670ab18](https://github.com/webpack-contrib/less-loader/commit/670ab18))
58
+
59
+
5
60
  <a name="4.0.4"></a>
6
61
  ## [4.0.4](https://github.com/webpack-contrib/less-loader/compare/v4.0.3...v4.0.4) (2017-05-30)
7
62
 
package/README.md CHANGED
@@ -1,279 +1,326 @@
1
- [![npm][npm]][npm-url]
2
- [![node][node]][node-url]
3
- [![npm-stats][npm-stats]][npm-url]
4
- [![deps][deps]][deps-url]
5
- [![travis][travis]][travis-url]
6
- [![appveyor][appveyor]][appveyor-url]
7
- [![coverage][coverage]][coverage-url]
8
- [![chat][chat]][chat-url]
9
-
10
1
  <div align="center">
11
- <img width="200" height="200"
12
- src="https://cdn.worldvectorlogo.com/logos/less-63.svg">
13
2
  <a href="https://github.com/webpack/webpack">
14
- <img width="200" height="200"
15
- src="https://webpack.js.org/assets/icon-square-big.svg">
3
+ <img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
16
4
  </a>
17
5
  </div>
18
6
 
19
- <h1 align="center">less-loader</h1>
7
+ [![npm][npm]][npm-url]
8
+ [![node][node]][node-url]
9
+ [![deps][deps]][deps-url]
10
+ [![tests][tests]][tests-url]
11
+ [![cover][cover]][cover-url]
12
+ [![chat][chat]][chat-url]
13
+ [![size][size]][size-url]
20
14
 
21
- <p align="center">Compiles Less to CSS.</p>
15
+ # less-loader
22
16
 
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.
17
+ A Less loader for webpack. Compiles Less to CSS.
24
18
 
19
+ ## Getting Started
25
20
 
26
- <h2 align="center">Install</h2>
21
+ To begin, you'll need to install `less-loader`:
27
22
 
28
- ```bash
29
- npm install --save-dev less-loader less
23
+ ```console
24
+ $ npm install less-loader --save-dev
30
25
  ```
31
26
 
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.
27
+ Then add the loader to your `webpack` config. For example:
33
28
 
34
- <h2 align="center">Examples</h2>
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.
29
+ **webpack.config.js**
37
30
 
38
31
  ```js
39
- // webpack.config.js
40
32
  module.exports = {
41
- ...
42
- module: {
43
- rules: [{
44
- test: /\.less$/,
45
- use: [{
46
- loader: "style-loader" // creates style nodes from JS strings
47
- }, {
48
- loader: "css-loader" // translates CSS into CommonJS
49
- }, {
50
- loader: "less-loader" // compiles Less to CSS
51
- }]
52
- }]
53
- }
33
+ module: {
34
+ rules: [
35
+ {
36
+ test: /\.less$/,
37
+ loader: 'less-loader', // compiles Less to CSS
38
+ },
39
+ ],
40
+ },
54
41
  };
55
42
  ```
56
43
 
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:
44
+ And run `webpack` via your preferred method.
45
+
46
+ The `less-loader` requires [less](https://github.com/less/less.js) as [`peerDependency`](https://docs.npmjs.com/files/package.json#peerdependencies).
47
+ Thus you are able to control the versions accurately.
48
+
49
+ ## Examples
50
+
51
+ Chain the `less-loader` with the
52
+ [`css-loader`](https://github.com/webpack-contrib/css-loader) and the
53
+ [`style-loader`](https://github.com/webpack-contrib/style-loader) to immediately
54
+ apply all styles to the DOM.
55
+
56
+ **webpack.config.js**
58
57
 
59
58
  ```js
60
- // webpack.config.js
61
59
  module.exports = {
62
- ...
63
- module: {
64
- rules: [{
65
- test: /\.less$/,
66
- use: [{
67
- loader: "style-loader"
68
- }, {
69
- loader: "css-loader"
70
- }, {
71
- loader: "less-loader", options: {
72
- strictMath: true,
73
- noIeCompat: true
74
- }
75
- }]
76
- }]
77
- }
60
+ module: {
61
+ rules: [
62
+ {
63
+ test: /\.less$/,
64
+ use: [
65
+ {
66
+ loader: 'style-loader', // creates style nodes from JS strings
67
+ },
68
+ {
69
+ loader: 'css-loader', // translates CSS into CommonJS
70
+ },
71
+ {
72
+ loader: 'less-loader', // compiles Less to CSS
73
+ },
74
+ ],
75
+ },
76
+ ],
77
+ },
78
78
  };
79
79
  ```
80
80
 
81
- Unfortunately, Less doesn't map all options 1-by-1 to camelCase. When in doubt, [check their executable and search for the dash-case option](https://github.com/less/less.js/blob/3.x/bin/lessc).
82
-
83
- ### In production
81
+ You can pass any Less specific options to the `less-loader` via [loader options](https://webpack.js.org/configuration/module/#rule-options-rule-query).
82
+ See the [Less documentation](http://lesscss.org/usage/#command-line-usage-options)
83
+ for all available options in dash-case. Since we're passing these options to
84
+ Less programmatically, you need to pass them in camelCase here:
84
85
 
85
- Usually, it's recommended to extract the style sheets into a dedicated file in production using the [ExtractTextPlugin](https://github.com/webpack-contrib/extract-text-webpack-plugin). This way your styles are not dependent on JavaScript:
86
+ **webpack.config.js**
86
87
 
87
88
  ```js
88
- const ExtractTextPlugin = require("extract-text-webpack-plugin");
89
-
90
- const extractLess = new ExtractTextPlugin({
91
- filename: "[name].[contenthash].css",
92
- disable: process.env.NODE_ENV === "development"
93
- });
94
-
95
89
  module.exports = {
96
- ...
97
- module: {
98
- rules: [{
99
- test: /\.less$/,
100
- use: extractLess.extract({
101
- use: [{
102
- loader: "css-loader"
103
- }, {
104
- loader: "less-loader"
105
- }],
106
- // use style-loader in development
107
- fallback: "style-loader"
108
- })
109
- }]
110
- },
111
- plugins: [
112
- extractLess
113
- ]
90
+ module: {
91
+ rules: [
92
+ {
93
+ test: /\.less$/,
94
+ use: [
95
+ {
96
+ loader: 'style-loader',
97
+ },
98
+ {
99
+ loader: 'css-loader',
100
+ },
101
+ {
102
+ loader: 'less-loader',
103
+ options: {
104
+ strictMath: true,
105
+ noIeCompat: true,
106
+ },
107
+ },
108
+ ],
109
+ },
110
+ ],
111
+ },
114
112
  };
115
113
  ```
116
114
 
117
- <h2 align="center">Usage</h2>
115
+ Unfortunately, Less doesn't map all options 1-by-1 to camelCase. When in doubt,
116
+ [check their executable](https://github.com/less/less.js/blob/3.x/bin/lessc)
117
+ and search for the dash-case option.
118
+
119
+ ### In production
120
+
121
+ Usually, it's recommended to extract the style sheets into a dedicated file in
122
+ production using the
123
+ [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin).
124
+ This way your styles are not dependent on JavaScript.
118
125
 
119
126
  ### Imports
120
127
 
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.
128
+ Starting with `less-loader` 4, you can now choose between Less' builtin resolver
129
+ and webpack's resolver. By default, webpack's resolver is used.
122
130
 
123
131
  #### webpack resolver
124
132
 
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).
133
+ webpack provides an
134
+ [advanced mechanism to resolve files](https://webpack.js.org/configuration/resolve/).
135
+ The `less-loader` applies a Less plugin that passes all queries to the webpack
136
+ resolver. Thus you can import your Less modules from `node_modules`. Just
137
+ prepend them with a `~` which tells webpack to look up the
138
+ [`modules`](https://webpack.js.org/configuration/resolve/#resolve-modules).
126
139
 
127
140
  ```css
128
- @import "~bootstrap/less/bootstrap";
141
+ @import '~bootstrap/less/bootstrap';
129
142
  ```
130
143
 
131
- 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";`
144
+ It's important to only prepend it with `~`, because `~/` resolves to the
145
+ home-directory. webpack needs to distinguish between `bootstrap` and
146
+ `~bootstrap`, because CSS and Less files have no special syntax for importing
147
+ relative files. Writing `@import "file"` is the same as `@import "./file";`
132
148
 
133
149
  ##### Non-Less imports
134
150
 
135
- 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:
151
+ Using webpack's resolver, you can import any file type. You just need a loader
152
+ that exports valid Less code. Often, you will also want to set the `issuer`
153
+ condition to ensure that this rule is only applied on imports originating from
154
+ Less files:
136
155
 
137
156
  ```js
138
157
  // webpack.config.js
139
158
  module.exports = {
140
- ...
141
- module: {
142
- rules: [{
143
- test: /\.js$/,
144
- issuer: /\.less$/,
145
- use: [{
146
- loader: "js-to-less-loader"
147
- }]
148
- }]
149
- }
159
+ module: {
160
+ rules: [
161
+ {
162
+ test: /\.js$/,
163
+ issuer: /\.less$/,
164
+ use: [
165
+ {
166
+ loader: 'js-to-less-loader',
167
+ },
168
+ ],
169
+ },
170
+ ],
171
+ },
150
172
  };
151
173
  ```
152
174
 
153
175
  #### Less resolver
154
176
 
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:
177
+ If you specify the `paths` option, the `less-loader` will not use webpack's
178
+ resolver. Modules, that can't be resolved in the local folder, will be searched
179
+ in the given `paths`. This is Less' default behavior. `paths` should be an array
180
+ with absolute paths:
181
+
182
+ **webpack.config.js**
156
183
 
157
184
  ```js
158
- // webpack.config.js
159
185
  module.exports = {
160
- ...
161
- module: {
162
- rules: [{
163
- test: /\.less$/,
164
- use: [{
165
- loader: "style-loader"
166
- }, {
167
- loader: "css-loader"
168
- }, {
169
- loader: "less-loader", options: {
170
- paths: [
171
- path.resolve(__dirname, "node_modules")
172
- ]
173
- }
174
- }]
175
- }]
176
- }
186
+ module: {
187
+ rules: [
188
+ {
189
+ test: /\.less$/,
190
+ use: [
191
+ {
192
+ loader: 'style-loader',
193
+ },
194
+ {
195
+ loader: 'css-loader',
196
+ },
197
+ {
198
+ loader: 'less-loader',
199
+ options: {
200
+ paths: [path.resolve(__dirname, 'node_modules')],
201
+ },
202
+ },
203
+ ],
204
+ },
205
+ ],
206
+ },
177
207
  };
178
208
  ```
179
209
 
180
- In this case, all webpack features like importing non-Less files or aliasing won't work of course.
210
+ In this case, all webpack features like importing non-Less files or aliasing
211
+ won't work of course.
181
212
 
182
213
  ### Plugins
183
214
 
184
- In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the `plugins` option like this:
215
+ In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the
216
+ `plugins` option like this:
185
217
 
186
218
  ```js
187
219
  // webpack.config.js
188
- const CleanCSSPlugin = require("less-plugin-clean-css");
220
+ const CleanCSSPlugin = require('less-plugin-clean-css');
189
221
 
190
222
  module.exports = {
191
- ...
192
- {
193
- loader: "less-loader", options: {
194
- plugins: [
195
- new CleanCSSPlugin({ advanced: true })
196
- ]
197
- }
198
- }]
199
- ...
223
+ ...
224
+ {
225
+ loader: 'less-loader', options: {
226
+ plugins: [
227
+ new CleanCSSPlugin({ advanced: true })
228
+ ]
229
+ }
230
+ }]
231
+ ...
200
232
  };
201
233
  ```
202
234
 
203
235
  ### Extracting style sheets
204
236
 
205
- 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.
237
+ Bundling CSS with webpack has some nice advantages like referencing images and
238
+ fonts with hashed urls or
239
+ [hot module replacement](https://webpack.js.org/concepts/hot-module-replacement/)
240
+ in development. In production, on the other hand, it's not a good idea to apply
241
+ your style sheets depending on JS execution. Rendering may be delayed or even a
242
+ [FOUC](https://en.wikipedia.org/wiki/Flash_of_unstyled_content) might be visible.
243
+ Thus it's often still better to have them as separate files in your final
244
+ production build.
206
245
 
207
246
  There are two possibilities to extract a style sheet from the bundle:
208
247
 
209
- - [extract-loader](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
210
- - [extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) (more complex, but works in all use-cases)
248
+ - [`extract-loader`](https://github.com/peerigon/extract-loader) (simpler, but
249
+ specialized on the css-loader's output)
250
+ - [MiniCssExtractPlugin](https://github.com/webpack-contrib/mini-css-extract-plugin)
251
+ (more complex, but works in all use-cases)
211
252
 
212
253
  ### Source maps
213
254
 
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:
255
+ To enable CSS source maps, you'll need to pass the `sourceMap` option to the
256
+ `less-loader` _and_ the `css-loader`. Your `webpack.config.js` should look
257
+ like this:
258
+
259
+ **webpack.config.js**
215
260
 
216
261
  ```javascript
217
262
  module.exports = {
218
- ...
219
- module: {
220
- rules: [{
221
- test: /\.less$/,
222
- use: [{
223
- loader: "style-loader"
224
- }, {
225
- loader: "css-loader", options: {
226
- sourceMap: true
227
- }
228
- }, {
229
- loader: "less-loader", options: {
230
- sourceMap: true
231
- }
232
- }]
233
- }]
234
- }
263
+ module: {
264
+ rules: [
265
+ {
266
+ test: /\.less$/,
267
+ use: [
268
+ {
269
+ loader: 'style-loader',
270
+ },
271
+ {
272
+ loader: 'css-loader',
273
+ options: {
274
+ sourceMap: true,
275
+ },
276
+ },
277
+ {
278
+ loader: 'less-loader',
279
+ options: {
280
+ sourceMap: true,
281
+ },
282
+ },
283
+ ],
284
+ },
285
+ ],
286
+ },
235
287
  };
236
288
  ```
237
289
 
238
290
  Also checkout the [sourceMaps example](https://github.com/webpack-contrib/less-loader/tree/master/examples/sourceMaps).
239
291
 
240
- If you want to edit the original Less files inside Chrome, [there's a good blog post](https://medium.com/@toolmantim/getting-started-with-css-sourcemaps-and-in-browser-sass-editing-b4daab987fb0). The blog post is about Sass but it also works for Less.
292
+ If you want to edit the original Less files inside Chrome,
293
+ [there's a good blog post](https://medium.com/@toolmantim/getting-started-with-css-sourcemaps-and-in-browser-sass-editing-b4daab987fb0).
294
+ The blog post is about Sass but it also works for Less.
241
295
 
242
296
  ### CSS modules gotcha
243
297
 
244
- There is a known problem with Less and [CSS modules](https://github.com/css-modules/css-modules) regarding relative file paths in `url(...)` statements. [See this issue for an explanation](https://github.com/webpack-contrib/less-loader/issues/109#issuecomment-253797335).
298
+ There is a known problem with Less and
299
+ [CSS modules](https://github.com/css-modules/css-modules) regarding relative
300
+ file paths in `url(...)` statements.
301
+ [See this issue for an explanation](https://github.com/webpack-contrib/less-loader/issues/109#issuecomment-253797335).
245
302
 
246
- <h2 align="center">Maintainer</h2>
303
+ ## Contributing
247
304
 
248
- <table>
249
- <tr>
250
- <td align="center">
251
- <a href="https://github.com/jhnns"><img width="150" height="150" src="https://github.com/jhnns.png?s=150"></a>
252
- <br>
253
- <a href="https://github.com/jhnns">Johannes Ewald</a>
254
- </td>
255
- <tr>
256
- </table>
305
+ Please take a moment to read our contributing guidelines if you haven't yet done so.
257
306
 
307
+ [CONTRIBUTING](./.github/CONTRIBUTING.md)
308
+
309
+ ## License
310
+
311
+ [MIT](./LICENSE)
258
312
 
259
313
  [npm]: https://img.shields.io/npm/v/less-loader.svg
260
- [npm-stats]: https://img.shields.io/npm/dm/less-loader.svg
261
314
  [npm-url]: https://npmjs.com/package/less-loader
262
-
263
315
  [node]: https://img.shields.io/node/v/less-loader.svg
264
316
  [node-url]: https://nodejs.org
265
-
266
317
  [deps]: https://david-dm.org/webpack-contrib/less-loader.svg
267
318
  [deps-url]: https://david-dm.org/webpack-contrib/less-loader
268
-
269
- [travis]: http://img.shields.io/travis/webpack-contrib/less-loader.svg
270
- [travis-url]: https://travis-ci.org/webpack-contrib/less-loader
271
-
272
- [appveyor-url]: https://ci.appveyor.com/project/jhnns/less-loader/branch/master
273
- [appveyor]: https://ci.appveyor.com/api/projects/status/github/webpack-contrib/less-loader?svg=true
274
-
275
- [coverage]: https://img.shields.io/codecov/c/github/webpack-contrib/less-loader.svg
276
- [coverage-url]: https://codecov.io/gh/webpack-contrib/less-loader
277
-
278
- [chat]: https://badges.gitter.im/webpack-contrib/webpack.svg
279
- [chat-url]: https://gitter.im/webpack-contrib/webpack
319
+ [tests]: https://dev.azure.com/webpack-contrib/less-loader/_apis/build/status/webpack-contrib.less-loader?branchName=master
320
+ [tests-url]: https://dev.azure.com/webpack-contrib/less-loader/_build/latest?definitionId=2&branchName=master
321
+ [cover]: https://codecov.io/gh/webpack-contrib/less-loader/branch/master/graph/badge.svg
322
+ [cover-url]: https://codecov.io/gh/webpack-contrib/less-loader
323
+ [chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
324
+ [chat-url]: https://gitter.im/webpack/webpack
325
+ [size]: https://packagephobia.now.sh/badge?p=less-loader
326
+ [size-url]: https://packagephobia.now.sh/result?p=less-loader
package/dist/cjs.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ module.exports = require('./index').default;
@@ -1,28 +1,27 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
3
+ /* eslint-disable class-methods-use-this */
4
+ const less = require('less');
4
5
 
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ const loaderUtils = require('loader-utils');
6
7
 
7
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
8
+ const pify = require('pify');
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
+ const stringifyLoader = require.resolve('./stringifyLoader.js');
10
11
 
11
- var less = require('less');
12
- var loaderUtils = require('loader-utils');
13
- var pify = require('pify');
14
-
15
- var stringifyLoader = require.resolve('./stringifyLoader.js');
16
- var trailingSlash = /[/\\]$/;
17
- var isLessCompatible = /\.(le|c)ss$/;
18
- // Less automatically adds a .less file extension if no extension was given.
12
+ const trailingSlash = /[/\\]$/;
13
+ const isLessCompatible = /\.(le|c)ss$/; // Less automatically adds a .less file extension if no extension was given.
19
14
  // This is problematic if there is a module request like @import "~some-module";
20
15
  // because in this case Less will call our file manager with `~some-module.less`.
21
16
  // Since dots in module names are highly discouraged, we can safely assume that
22
17
  // this is an error and we need to remove the .less extension again.
23
18
  // However, we must not match something like @import "~some-module/file.less";
24
- var matchMalformedModuleFilename = /(~[^/\\]+)\.less$/;
25
19
 
20
+ const matchMalformedModuleFilename = /(~[^/\\]+)\.less$/; // This somewhat changed in Less 3.x. Now the file name comes without the
21
+ // automatically added extension whereas the extension is passed in as `options.ext`.
22
+ // So, if the file name matches this regexp, we simply ignore the proposed extension.
23
+
24
+ const isModuleName = /^~[^/\\]+$/;
26
25
  /**
27
26
  * Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext.
28
27
  *
@@ -30,66 +29,71 @@ var matchMalformedModuleFilename = /(~[^/\\]+)\.less$/;
30
29
  * @param {string=} root
31
30
  * @returns {LessPlugin}
32
31
  */
33
- function createWebpackLessPlugin(loaderContext) {
34
- var fs = loaderContext.fs;
35
-
36
- var resolve = pify(loaderContext.resolve.bind(loaderContext));
37
- var loadModule = pify(loaderContext.loadModule.bind(loaderContext));
38
- var readFile = pify(fs.readFile.bind(fs));
39
-
40
- var WebpackFileManager = function (_less$FileManager) {
41
- _inherits(WebpackFileManager, _less$FileManager);
42
-
43
- function WebpackFileManager() {
44
- _classCallCheck(this, WebpackFileManager);
45
32
 
46
- return _possibleConstructorReturn(this, (WebpackFileManager.__proto__ || Object.getPrototypeOf(WebpackFileManager)).apply(this, arguments));
33
+ function createWebpackLessPlugin(loaderContext) {
34
+ const {
35
+ fs
36
+ } = loaderContext;
37
+ const resolve = pify(loaderContext.resolve.bind(loaderContext));
38
+ const loadModule = pify(loaderContext.loadModule.bind(loaderContext));
39
+ const readFile = pify(fs.readFile.bind(fs));
40
+
41
+ class WebpackFileManager extends less.FileManager {
42
+ supports() {
43
+ // Our WebpackFileManager handles all the files
44
+ return true;
45
+ } // Sync resolving is used at least by the `data-uri` function.
46
+ // This file manager doesn't know how to do it, so let's delegate it
47
+ // to the default file manager of Less.
48
+ // We could probably use loaderContext.resolveSync, but it's deprecated,
49
+ // see https://webpack.js.org/api/loaders/#this-resolvesync
50
+
51
+
52
+ supportsSync() {
53
+ return false;
47
54
  }
48
55
 
49
- _createClass(WebpackFileManager, [{
50
- key: 'supports',
51
- value: function supports() /* filename, currentDirectory, options, environment */{
52
- // eslint-disable-line class-methods-use-this
53
- // Our WebpackFileManager handles all the files
54
- return true;
55
- }
56
- }, {
57
- key: 'loadFile',
58
- value: function loadFile(filename, currentDirectory /* , options, environment */) {
59
- // eslint-disable-line class-methods-use-this
60
- var url = filename.replace(matchMalformedModuleFilename, '$1');
61
- var moduleRequest = loaderUtils.urlToRequest(url, url.charAt(0) === '/' ? '' : null);
62
- // Less is giving us trailing slashes, but the context should have no trailing slash
63
- var context = currentDirectory.replace(trailingSlash, '');
64
- var resolvedFilename = void 0;
65
-
66
- return resolve(context, moduleRequest).then(function (f) {
67
- resolvedFilename = f;
68
- loaderContext.addDependency(resolvedFilename);
69
-
70
- if (isLessCompatible.test(resolvedFilename)) {
71
- return readFile(resolvedFilename).then(function (contents) {
72
- return contents.toString('utf8');
73
- });
74
- }
75
-
76
- return loadModule([stringifyLoader, resolvedFilename].join('!')).then(JSON.parse);
77
- }).then(function (contents) {
78
- return {
79
- contents,
80
- filename: resolvedFilename
81
- };
82
- });
56
+ loadFile(filename, currentDirectory, options) {
57
+ let url;
58
+
59
+ if (less.version[0] >= 3) {
60
+ if (options.ext && !isModuleName.test(filename)) {
61
+ url = this.tryAppendExtension(filename, options.ext);
62
+ } else {
63
+ url = filename;
64
+ }
65
+ } else {
66
+ url = filename.replace(matchMalformedModuleFilename, '$1');
83
67
  }
84
- }]);
85
68
 
86
- return WebpackFileManager;
87
- }(less.FileManager);
69
+ const moduleRequest = loaderUtils.urlToRequest(url, url.charAt(0) === '/' ? '' : null); // Less is giving us trailing slashes, but the context should have no trailing slash
70
+
71
+ const context = currentDirectory.replace(trailingSlash, '');
72
+ let resolvedFilename;
73
+ return resolve(context, moduleRequest).then(f => {
74
+ resolvedFilename = f;
75
+ loaderContext.addDependency(resolvedFilename);
76
+
77
+ if (isLessCompatible.test(resolvedFilename)) {
78
+ return readFile(resolvedFilename).then(contents => contents.toString('utf8'));
79
+ }
80
+
81
+ return loadModule([stringifyLoader, resolvedFilename].join('!')).then(JSON.parse);
82
+ }).then(contents => {
83
+ return {
84
+ contents,
85
+ filename: resolvedFilename
86
+ };
87
+ });
88
+ }
89
+
90
+ }
88
91
 
89
92
  return {
90
93
  install(lessInstance, pluginManager) {
91
94
  pluginManager.addFileManager(new WebpackFileManager());
92
95
  },
96
+
93
97
  minVersion: [2, 1, 1]
94
98
  };
95
99
  }
@@ -1,9 +1,6 @@
1
- 'use strict';
2
-
3
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
4
-
5
- var os = require('os');
1
+ "use strict";
6
2
 
3
+ const os = require('os');
7
4
  /**
8
5
  * Tries to get an excerpt of the file where the error happened.
9
6
  * Uses err.line and err.column.
@@ -13,24 +10,24 @@ var os = require('os');
13
10
  * @param {LessError} err
14
11
  * @returns {Array<string>}
15
12
  */
13
+
14
+
16
15
  function getFileExcerptIfPossible(lessErr) {
17
16
  try {
18
- var excerpt = lessErr.extract.slice(0, 2);
19
- var column = Math.max(lessErr.column - 1, 0);
17
+ const excerpt = lessErr.extract.slice(0, 2);
18
+ const column = Math.max(lessErr.column - 1, 0);
20
19
 
21
20
  if (typeof excerpt[0] === 'undefined') {
22
21
  excerpt.shift();
23
22
  }
24
23
 
25
24
  excerpt.push(`${new Array(column).join(' ')}^`);
26
-
27
25
  return excerpt;
28
26
  } catch (unexpectedErr) {
29
27
  // If anything goes wrong here, we don't want any errors to be reported to the user
30
28
  return [];
31
29
  }
32
30
  }
33
-
34
31
  /**
35
32
  * Beautifies the error message from Less.
36
33
  *
@@ -46,17 +43,18 @@ function getFileExcerptIfPossible(lessErr) {
46
43
  * @param {Array<string>} lessErr.extract - e.g. [' .my-style {', ' .undefined-mixin;', ' display: block;']
47
44
  * @returns {LessError}
48
45
  */
46
+
47
+
49
48
  function formatLessError(err) {
50
49
  /* eslint-disable no-param-reassign */
51
- var msg = err.message;
52
-
53
- // Instruct webpack to hide the JS stack from the console
50
+ const msg = err.message; // Instruct webpack to hide the JS stack from the console
54
51
  // Usually you're only interested in the SASS stack in this case.
55
- err.hideStack = true;
56
-
57
- err.message = [os.EOL].concat(_toConsumableArray(getFileExcerptIfPossible(err)), [msg.charAt(0).toUpperCase() + msg.slice(1), ` in ${err.filename} (line ${err.line}, column ${err.column})`]).join(os.EOL);
58
52
 
53
+ err.hideStack = true;
54
+ err.message = [os.EOL, ...getFileExcerptIfPossible(err), msg.charAt(0).toUpperCase() + msg.slice(1), ` in ${err.filename} (line ${err.line}, column ${err.column})`].join(os.EOL);
59
55
  return err;
60
- } /* eslint-enable no-param-reassign */
56
+ }
57
+ /* eslint-enable no-param-reassign */
58
+
61
59
 
62
60
  module.exports = formatLessError;
@@ -1,25 +1,30 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var loaderUtils = require('loader-utils');
4
- var clone = require('clone');
5
- var createWebpackLessPlugin = require('./createWebpackLessPlugin');
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
6
4
 
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ const loaderUtils = require('loader-utils');
8
+
9
+ const clone = require('clone');
10
+
11
+ const createWebpackLessPlugin = require('./createWebpackLessPlugin');
7
12
  /**
8
13
  * Retrieves the options from the loaderContext, makes a deep copy of it and normalizes it for further consumption.
9
14
  *
10
15
  * @param {LoaderContext} loaderContext
11
16
  */
17
+
18
+
12
19
  function getOptions(loaderContext) {
13
- var options = Object.assign({
20
+ const options = _objectSpread({
14
21
  plugins: [],
15
- relativeUrls: true,
16
- compress: Boolean(loaderContext.minimize)
17
- }, clone(loaderUtils.getOptions(loaderContext)));
22
+ relativeUrls: true
23
+ }, clone(loaderUtils.getOptions(loaderContext))); // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
24
+
18
25
 
19
- // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
20
- options.filename = loaderContext.resource;
26
+ options.filename = loaderContext.resource; // When no paths are given, we use the webpack resolver
21
27
 
22
- // When no paths are given, we use the webpack resolver
23
28
  if ('paths' in options === false) {
24
29
  // It's safe to mutate the array now because it has already been cloned
25
30
  options.plugins.push(createWebpackLessPlugin(loaderContext));
@@ -29,6 +34,7 @@ function getOptions(loaderContext) {
29
34
  if (typeof options.sourceMap === 'boolean') {
30
35
  options.sourceMap = {};
31
36
  }
37
+
32
38
  if ('outputSourceFiles' in options.sourceMap === false) {
33
39
  // Include source files as `sourceContents` as sane default since this makes source maps "just work" in most cases
34
40
  options.sourceMap.outputSourceFiles = true;
package/dist/index.js CHANGED
@@ -1,23 +1,34 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var less = require('less');
4
- var pify = require('pify');
5
- var processResult = require('./processResult');
6
- var getOptions = require('./getOptions');
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
7
 
8
- var render = pify(less.render.bind(less));
8
+ var _less = _interopRequireDefault(require("less"));
9
+
10
+ var _pify = _interopRequireDefault(require("pify"));
11
+
12
+ var _processResult = _interopRequireDefault(require("./processResult"));
13
+
14
+ var _getOptions = _interopRequireDefault(require("./getOptions"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ const render = (0, _pify.default)(_less.default.render.bind(_less.default));
9
19
 
10
20
  function lessLoader(source) {
11
- var loaderContext = this;
12
- var options = getOptions(loaderContext);
13
- var done = loaderContext.async();
14
- var isSync = typeof done !== 'function';
21
+ const loaderContext = this;
22
+ const options = (0, _getOptions.default)(loaderContext);
23
+ const done = loaderContext.async();
24
+ const isSync = typeof done !== 'function';
15
25
 
16
26
  if (isSync) {
17
27
  throw new Error('Synchronous compilation is not supported anymore. See https://github.com/webpack-contrib/less-loader/issues/84');
18
28
  }
19
29
 
20
- processResult(loaderContext, render(source, options));
30
+ (0, _processResult.default)(loaderContext, render(source, options));
21
31
  }
22
32
 
23
- module.exports = lessLoader;
33
+ var _default = lessLoader;
34
+ exports.default = _default;
@@ -1,23 +1,25 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var removeSourceMappingUrl = require('./removeSourceMappingUrl');
4
- var formatLessError = require('./formatLessError');
3
+ const removeSourceMappingUrl = require('./removeSourceMappingUrl');
5
4
 
5
+ const formatLessError = require('./formatLessError');
6
6
  /**
7
7
  * Removes the sourceMappingURL from the generated CSS, parses the source map and calls the next loader.
8
8
  *
9
9
  * @param {loaderContext} loaderContext
10
10
  * @param {Promise<LessResult>} resultPromise
11
11
  */
12
- function processResult(loaderContext, resultPromise) {
13
- var callback = loaderContext.callback;
14
-
15
12
 
16
- resultPromise.then(function (_ref) {
17
- var css = _ref.css,
18
- map = _ref.map,
19
- imports = _ref.imports;
20
13
 
14
+ function processResult(loaderContext, resultPromise) {
15
+ const {
16
+ callback
17
+ } = loaderContext;
18
+ resultPromise.then(({
19
+ css,
20
+ map,
21
+ imports
22
+ }) => {
21
23
  imports.forEach(loaderContext.addDependency, loaderContext);
22
24
  return {
23
25
  // Removing the sourceMappingURL comment.
@@ -25,12 +27,16 @@ function processResult(loaderContext, resultPromise) {
25
27
  css: removeSourceMappingUrl(css),
26
28
  map: typeof map === 'string' ? JSON.parse(map) : map
27
29
  };
28
- }, function (lessError) {
29
- throw formatLessError(lessError);
30
- }).then(function (_ref2) {
31
- var css = _ref2.css,
32
- map = _ref2.map;
30
+ }, lessError => {
31
+ if (lessError.filename) {
32
+ loaderContext.addDependency(lessError.filename);
33
+ }
33
34
 
35
+ throw formatLessError(lessError);
36
+ }).then(({
37
+ css,
38
+ map
39
+ }) => {
34
40
  callback(null, css, map);
35
41
  }, callback);
36
42
  }
@@ -1,7 +1,6 @@
1
- 'use strict';
2
-
3
- var matchSourceMappingUrl = /\/\*# sourceMappingURL=[^*]+\*\//;
1
+ "use strict";
4
2
 
3
+ const matchSourceMappingUrl = /\/\*# sourceMappingURL=[^*]+\*\//;
5
4
  /**
6
5
  * Removes the sourceMappingURL comment. This is necessary because the less-loader
7
6
  * does not know where the final source map will be located. Thus, we remove every
@@ -12,6 +11,7 @@ var matchSourceMappingUrl = /\/\*# sourceMappingURL=[^*]+\*\//;
12
11
  * @param {string} content
13
12
  * @returns {string}
14
13
  */
14
+
15
15
  function removeSourceMappingUrl(content) {
16
16
  return content.replace(matchSourceMappingUrl, '');
17
17
  }
package/package.json CHANGED
@@ -1,82 +1,81 @@
1
1
  {
2
2
  "name": "less-loader",
3
- "version": "4.0.4",
3
+ "version": "5.0.0",
4
+ "description": "A Less loader for webpack. Compiles Less to CSS.",
5
+ "license": "MIT",
6
+ "repository": "webpack-contrib/less-loader",
4
7
  "author": "Johannes Ewald @jhnns",
5
- "description": "Less loader for webpack. Compiles Less to CSS.",
6
- "main": "dist/index.js",
8
+ "homepage": "https://github.com/webpack-contrib/less-loader",
9
+ "bugs": "https://github.com/webpack-contrib/less-loader/issues",
10
+ "main": "dist/cjs.js",
11
+ "engines": {
12
+ "node": ">= 4.8.0"
13
+ },
7
14
  "scripts": {
8
- "create-spec": "babel-node test/helpers/createSpec.js",
9
- "pretest": "npm run create-spec",
10
- "test": "jest",
11
- "posttest": "npm run lint",
12
- "travis:test": "yarn run test",
13
- "appveyor:test": "npm test",
15
+ "start": "npm run build -- -w",
16
+ "prebuild": "npm run clean",
17
+ "build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
18
+ "build:fixtures": "babel-node test/helpers/createSpec.js",
19
+ "clean": "del-cli dist",
20
+ "commitlint": "commitlint --from=master",
14
21
  "lint": "eslint --cache src test",
15
- "webpack-defaults": "webpack-defaults",
16
- "start": "yarn run build -- -w",
17
- "build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
18
- "clean:dist": "del-cli dist",
19
- "lint-staged": "lint-staged",
20
- "prebuild": "yarn run clean",
21
- "prepublish": "yarn run build",
22
- "release": "yarn run standard-version",
23
- "security": "nsp check",
24
- "serve:dev": "nodemon $2 --exec babel-node",
25
- "test:watch": "jest --watch",
26
- "test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
27
- "travis:coverage": "yarn run test:coverage",
28
- "travis:lint": "yarn run lint && yarn run security",
29
- "clean": "del-cli dist"
22
+ "prepare": "npm run build",
23
+ "release": "standard-version",
24
+ "security": "npm audit",
25
+ "test:only": "cross-env NODE_ENV=test npm run build:fixtures && jest",
26
+ "test:watch": "cross-env NODE_ENV=test npm run build:fixtures && jest --watch",
27
+ "test:coverage": "cross-env NODE_ENV=test npm run build:fixtures && jest --collectCoverageFrom='src/**/*.js' --coverage",
28
+ "pretest": "npm run lint",
29
+ "test": "cross-env NODE_ENV=test npm run test:coverage",
30
+ "defaults": "webpack-defaults"
30
31
  },
31
- "engines": {
32
- "node": ">= 4.3 < 5.0.0 || >= 5.10"
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "peerDependencies": {
36
+ "less": "^2.3.1 || ^3.0.0",
37
+ "webpack": "^2.0.0 || ^3.0.0 || ^4.0.0"
33
38
  },
34
39
  "dependencies": {
35
40
  "clone": "^2.1.1",
36
41
  "loader-utils": "^1.1.0",
37
- "pify": "^2.3.0"
38
- },
39
- "peerDependencies": {
40
- "less": "^2.3.1",
41
- "webpack": "^2.2.0"
42
+ "pify": "^4.0.1"
42
43
  },
43
44
  "devDependencies": {
44
- "babel-cli": "^6.24.0",
45
- "babel-jest": "^20.0.3",
46
- "babel-plugin-transform-object-rest-spread": "^6.23.0",
47
- "babel-polyfill": "^6.23.0",
48
- "babel-preset-env": "^1.2.2",
49
- "cross-env": "^3.2.4",
50
- "del-cli": "^0.2.1",
51
- "eslint": "^3.18.0",
52
- "eslint-config-webpack": "^1.2.1",
53
- "eslint-plugin-import": "^2.2.0",
45
+ "@babel/cli": "^7.4.4",
46
+ "@babel/core": "^7.4.4",
47
+ "@babel/node": "^7.2.2",
48
+ "@babel/preset-env": "^7.4.4",
49
+ "@commitlint/cli": "^7.5.2",
50
+ "@commitlint/config-conventional": "^7.5.0",
51
+ "@webpack-contrib/defaults": "^4.0.1",
52
+ "@webpack-contrib/eslint-config-webpack": "^3.0.0",
53
+ "babel-jest": "^24.7.1",
54
+ "commitlint-azure-pipelines-cli": "^1.0.1",
55
+ "cross-env": "^5.2.0",
56
+ "del": "^4.1.1",
57
+ "del-cli": "^1.1.0",
58
+ "eslint": "^5.16.0",
59
+ "eslint-plugin-import": "^2.17.2",
60
+ "eslint-plugin-prettier": "^3.0.1",
61
+ "husky": "^2.1.0",
54
62
  "inspect-loader": "^1.0.0",
55
- "jest": "^20.0.3",
56
- "less": "^2.3.1",
57
- "lint-staged": "^3.4.0",
58
- "nodemon": "^1.11.0",
59
- "nsp": "^2.6.3",
60
- "pre-commit": "^1.2.2",
61
- "standard-version": "^4.0.0",
62
- "webpack": "^2.3.2",
63
- "webpack-defaults": "^1.0.1"
63
+ "jest": "^24.7.1",
64
+ "jest-junit": "^6.3.0",
65
+ "less": "^3.9.0",
66
+ "lint-staged": "^8.1.5",
67
+ "memory-fs": "^0.4.1",
68
+ "prettier": "^1.17.0",
69
+ "standard-version": "^5.0.2",
70
+ "webpack": "^4.30.0"
64
71
  },
65
- "repository": {
66
- "type": "git",
67
- "url": "git://github.com/webpack-contrib/less-loader.git"
68
- },
69
- "license": "MIT",
70
- "files": [
71
- "README.md",
72
- "LICENSE",
73
- "dist"
74
- ],
75
- "pre-commit": "lint-staged",
76
- "lint-staged": {
77
- "*.js": [
78
- "eslint --fix",
79
- "git add"
80
- ]
81
- }
72
+ "keywords": [
73
+ "webpack",
74
+ "loader",
75
+ "less",
76
+ "lesscss",
77
+ "less.js",
78
+ "css",
79
+ "preprocessor"
80
+ ]
82
81
  }