less-loader 2.1.0 → 2.2.3

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/.travis.yml CHANGED
@@ -1,4 +1,13 @@
1
+ sudo: false
1
2
  language: node_js
2
3
  node_js:
3
4
  - "0.10"
4
- - "0.11"
5
+ - "0.11"
6
+ - "0.12"
7
+ - "4"
8
+ script:
9
+ - "npm test"
10
+ # test with npm@3
11
+ - "rm -rf node_modules && npm install npm@3"
12
+ - "node_modules/.bin/npm install"
13
+ - "node_modules/.bin/npm test"
package/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ Changelog
2
+ ---------
3
+
4
+ ### 2.2.3
5
+
6
+ - Fix missing path information in source map [#73](https://github.com/webpack/less-loader/pull/73)
7
+ - Add deprecation warning [#84](https://github.com/webpack/less-loader/issues/84)
8
+
9
+ ### 2.2.2
10
+
11
+ - Fix issues with synchronous less functions like `data-uri()`, `image-size()`, `image-width()`, `image-height()` [#31](https://github.com/webpack/less-loader/issues/31) [#38](https://github.com/webpack/less-loader/issues/38) [#43](https://github.com/webpack/less-loader/issues/43) [#58](https://github.com/webpack/less-loader/pull/58)
12
+
13
+ ### 2.2.1
14
+
15
+ - Improve Readme
16
+
17
+ ### 2.2.0
18
+
19
+ - Added option to specify LESS plugins [#40](https://github.com/webpack/less-loader/pull/40)
package/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2015 Tobias Koppers
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,78 +1,90 @@
1
- # less loader for webpack
2
-
3
- ## Usage
4
-
5
- [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
6
-
7
- ``` javascript
8
- var css = require("!raw!less!./file.less");
9
- // => returns compiled css code from file.less, resolves imports
10
- var css = require("!css!less!./file.less");
11
- // => returns compiled css code from file.less, resolves imports and url(...)s
12
- ```
13
-
14
- Use in tandem with the [`style-loader`](https://github.com/webpack/style-loader) to add the css rules to your document:
15
-
16
- ``` javascript
17
- require("!style!css!less!./file.less");
18
- ```
19
-
20
- ### webpack config
21
-
22
- ``` javascript
23
- module.exports = {
24
- module: {
25
- loaders: [
26
- {
27
- test: /\.less$/,
28
- loader: "style!css!less"
29
- }
30
- ]
31
- }
32
- };
33
- ```
34
-
35
- Then you only need to write: `require("./file.less")`
36
-
37
- ### LESS options
38
-
39
- You can pass any LESS specific configuration options through to the render function via [query parameters](http://webpack.github.io/docs/using-loaders.html#query-parameters).
40
-
41
- ``` javascript
42
- module.exports = {
43
- module: {
44
- loaders: [
45
- {
46
- test: /\.less$/,
47
- loader: "style!css!less?strictMath&noIeCompat"
48
- }
49
- ]
50
- }
51
- };
1
+ # less loader for webpack
2
+
3
+ ## Installation
4
+
5
+ `npm install less-loader --save-dev`
6
+
7
+ ## Usage
8
+
9
+ [Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
10
+
11
+ ``` javascript
12
+ var css = require("!raw!less!./file.less");
13
+ // => returns compiled css code from file.less, resolves imports
14
+ var css = require("!css!less!./file.less");
15
+ // => returns compiled css code from file.less, resolves imports and url(...)s
16
+ ```
17
+
18
+ Use in tandem with the [`style-loader`](https://github.com/webpack/style-loader) to add the css rules to your document:
19
+
20
+ ``` javascript
21
+ require("!style!css!less!./file.less");
22
+ ```
23
+
24
+ ### webpack config
25
+
26
+ ``` javascript
27
+ module.exports = {
28
+ module: {
29
+ loaders: [
30
+ {
31
+ test: /\.less$/,
32
+ loader: "style!css!less"
33
+ }
34
+ ]
35
+ }
36
+ };
37
+ ```
38
+
39
+ Then you only need to write: `require("./file.less")`
40
+
41
+ ### LESS options
42
+
43
+ You can pass any LESS specific configuration options through to the render function via [query parameters](http://webpack.github.io/docs/using-loaders.html#query-parameters).
44
+
45
+ ``` javascript
46
+ module.exports = {
47
+ module: {
48
+ loaders: [
49
+ {
50
+ test: /\.less$/,
51
+ loader: "style!css!less?strictMath&noIeCompat"
52
+ }
53
+ ]
54
+ }
55
+ };
56
+ ```
57
+
58
+ See the [LESS documentation](http://lesscss.org/usage/#command-line-usage-options) for all available options. LESS translates dash-case to camelCase. Certain options which take values (e.g. `lessc --modify-var="a=b"`) are better handled with the [JSON loader syntax](http://webpack.github.io/docs/using-loaders.html#query-parameters) (`style!css!less?{"modifyVars":{"a":"b"}}`).
59
+
60
+ ### LESS plugins
61
+
62
+ In order to use [plugins](http://lesscss.org/usage/#plugins), simply set
63
+ the `lessLoader.lessPlugins`-option on your webpack options. You can also change the options' key with a query parameter: `"less?config=lessLoaderCustom"`.
64
+
65
+ ``` javascript
66
+ var LessPluginCleanCSS = require('less-plugin-clean-css');
67
+
68
+ module.exports = {
69
+ ...
70
+ lessLoader: {
71
+ lessPlugins: [
72
+ new LessPluginCleanCSS({advanced: true})
73
+ ]
74
+ }
75
+ };
52
76
  ```
53
77
 
54
- See the [LESS documentation](http://lesscss.org/usage/#command-line-usage-options) for all available options. LESS translates dash-case to camelCase.
55
-
56
- ## Note on imports
57
-
58
- webpack provides an [advanced mechanism to resolve files](http://webpack.github.io/docs/resolving.html). The less-loader stubs less' `fileLoader` and passes all queries to the webpack resolving engine. Thus you can import your less-modules from `node_modules` or `bower_components`. Just prepend them with a `~` which tells webpack to look-up the [`modulesDirectories`](http://webpack.github.io/docs/configuration.html#resolve-modulesdirectories)
59
-
60
- ```css
61
- @import "~bootstrap/less/bootstrap";
62
- ```
63
-
64
- It's important to only prepend it with `~`, because `~/` resolves to the home-directory. webpack needs to distinguish `bootstrap` from `~bootstrap` because css- and less-files have no special syntax for importing relative files:
65
-
66
- ```css
67
- @import "file";
68
- ```
69
-
70
- is the same as
71
-
72
- ```css
73
- @import "./file";
78
+ ## Imports
79
+
80
+ webpack provides an [advanced mechanism to resolve files](http://webpack.github.io/docs/resolving.html). The less-loader stubs less' `fileLoader` and passes all queries to the webpack resolving engine. Thus you can import your less-modules from `node_modules`. Just prepend them with a `~` which tells webpack to look-up the [`modulesDirectories`](http://webpack.github.io/docs/configuration.html#resolve-modulesdirectories)
81
+
82
+ ```css
83
+ @import "~bootstrap/less/bootstrap";
74
84
  ```
75
85
 
86
+ 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";`
87
+
76
88
  ## Source maps
77
89
 
78
90
  Because of browser limitations, source maps are only available in conjunction with the [extract-text-webpack-plugin](https://github.com/webpack/extract-text-webpack-plugin). Use that plugin to extract the CSS code from the generated JS bundle into a separate file (which even improves the perceived performance because JS and CSS are loaded in parallel).
@@ -105,16 +117,16 @@ module.exports = {
105
117
  };
106
118
  ```
107
119
 
108
- If you want to view the original LESS files inside Chrome and even edit it, [there's a good blog post](https://medium.com/@toolmantim/getting-started-with-css-sourcemaps-and-in-browser-sass-editing-b4daab987fb0). Checkout [test/sourceMap](https://github.com/webpack/less-loader/tree/master/test) for a running example. Make sure to serve the content with an HTTP server.
109
-
110
- ## Contribution
111
-
112
- Don't hesitate to create a pull request. Every contribution is appreciated. In development you can start the tests by calling `npm test`.
113
-
114
- The tests are basically just comparing the generated css with a reference css-file located under `test/css`. You can easily generate a reference css-file by calling `node test/helpers/generateCss.js <less-file-without-less-extension>`. It passes the less-file to less and writes the output to the `test/css`-folder.
115
-
116
- [![build status](https://travis-ci.org/webpack/less-loader.svg)](https://travis-ci.org/webpack/less-loader)
117
-
118
- ## License
119
-
120
- MIT (http://www.opensource.org/licenses/mit-license.php)
120
+ If you want to view the original LESS files inside Chrome and even edit it, [there's a good blog post](https://medium.com/@toolmantim/getting-started-with-css-sourcemaps-and-in-browser-sass-editing-b4daab987fb0). Checkout [test/sourceMap](https://github.com/webpack/less-loader/tree/master/test) for a running example. Make sure to serve the content with an HTTP server.
121
+
122
+ ## Contribution
123
+
124
+ Don't hesitate to create a pull request. Every contribution is appreciated. In development you can start the tests by calling `npm test`.
125
+
126
+ The tests are basically just comparing the generated css with a reference css-file located under `test/css`. You can easily generate a reference css-file by calling `node test/helpers/generateCss.js <less-file-without-less-extension>`. It passes the less-file to less and writes the output to the `test/css`-folder.
127
+
128
+ [![build status](https://travis-ci.org/webpack/less-loader.svg)](https://travis-ci.org/webpack/less-loader)
129
+
130
+ ## License
131
+
132
+ MIT (http://www.opensource.org/licenses/mit-license.php)
package/index.js CHANGED
@@ -9,6 +9,7 @@ var less = require("less");
9
9
  var fs = require("fs");
10
10
  var loaderUtils = require("loader-utils");
11
11
  var path = require("path");
12
+ var util = require("util");
12
13
 
13
14
  var trailingSlash = /[\\\/]$/;
14
15
 
@@ -18,6 +19,7 @@ module.exports = function(source) {
18
19
  var cb = this.async();
19
20
  var isSync = typeof cb !== "function";
20
21
  var finalCb = cb || this.callback;
22
+ var configKey = query.config || "lessLoader";
21
23
  var config = {
22
24
  filename: this.resource,
23
25
  paths: [],
@@ -44,6 +46,11 @@ module.exports = function(source) {
44
46
  config.plugins = config.plugins || [];
45
47
  config.plugins.push(webpackPlugin);
46
48
 
49
+ // If present, add custom LESS plugins.
50
+ if (this.options[configKey]) {
51
+ config.plugins = config.plugins.concat(this.options[configKey].lessPlugins || []);
52
+ }
53
+
47
54
  // not using the `this.sourceMap` flag because css source maps are different
48
55
  // @see https://github.com/webpack/css-loader/pull/40
49
56
  if (query.sourceMap) {
@@ -53,7 +60,6 @@ module.exports = function(source) {
53
60
  }
54
61
 
55
62
  less.render(source, config, function(e, result) {
56
- var parsedMap;
57
63
  var cb = finalCb;
58
64
  // Less is giving us double callbacks sometimes :(
59
65
  // Thus we need to mark the callback as "has been called"
@@ -61,16 +67,6 @@ module.exports = function(source) {
61
67
  finalCb = null;
62
68
  if(e) return cb(formatLessRenderError(e));
63
69
 
64
- if (result.map) {
65
- parsedMap = JSON.parse(result.map);
66
-
67
- parsedMap.sources = parsedMap.sources.map(function(file) {
68
- return path.basename(file);
69
- });
70
-
71
- result.map = JSON.stringify(parsedMap);
72
- }
73
-
74
70
  cb(null, result.css, result.map);
75
71
  });
76
72
  };
@@ -88,7 +84,9 @@ function getWebpackFileManager(less, loaderContext, query, isSync) {
88
84
  return true;
89
85
  };
90
86
 
91
- WebpackFileManager.prototype.supportsSync = WebpackFileManager.prototype.supports;
87
+ WebpackFileManager.prototype.supportsSync = function(filename, currentDirectory, options, environment) {
88
+ return isSync;
89
+ };
92
90
 
93
91
  WebpackFileManager.prototype.loadFile = function(filename, currentDirectory, options, environment, callback) {
94
92
  // Unfortunately we don't have any influence on less to call `loadFile` or `loadFileSync`
@@ -130,7 +128,7 @@ function getWebpackFileManager(less, loaderContext, query, isSync) {
130
128
  });
131
129
  };
132
130
 
133
- WebpackFileManager.prototype.loadFileSync = function(filename, currentDirectory, options, environment) {
131
+ WebpackFileManager.prototype.loadFileSync = util.deprecate(function(filename, currentDirectory, options, environment) {
134
132
  var moduleRequest = loaderUtils.urlToRequest(filename, query.root);
135
133
  // Less is giving us trailing slashes, but the context should have no trailing slash
136
134
  var context = currentDirectory.replace(trailingSlash, "");
@@ -144,7 +142,7 @@ function getWebpackFileManager(less, loaderContext, query, isSync) {
144
142
  contents: data,
145
143
  filename: filename
146
144
  };
147
- };
145
+ }, "We are planing to remove enhanced-require support with the next major release of the less-loader: https://github.com/webpack/less-loader/issues/84");
148
146
 
149
147
  return WebpackFileManager;
150
148
  }
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "less-loader",
3
- "version": "2.1.0",
3
+ "version": "2.2.3",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "less loader module for webpack",
6
6
  "scripts": {
7
- "test": "mocha -R spec",
7
+ "test": "node --no-deprecation node_modules/.bin/_mocha -R spec",
8
8
  "test-source-map": "webpack --config test/sourceMap/webpack.config.js && open ./test/sourceMap/index.html"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "less": "^2.3.1"
12
12
  },
13
13
  "devDependencies": {
14
- "css-loader": "^0.9.1",
14
+ "css-loader": "^0.23.1",
15
15
  "enhanced-require": "^0.5.0-beta6",
16
- "extract-text-webpack-plugin": "^0.3.8",
17
- "less": "^2.3.1",
18
- "mocha": "^2.0.1",
16
+ "extract-text-webpack-plugin": "^1.0.1",
17
+ "less": "^2.6.1",
18
+ "mocha": "^2.4.5",
19
19
  "raw-loader": "^0.5.1",
20
- "should": "^4.4.1",
21
- "webpack": "^1.1.8"
20
+ "should": "^8.3.0",
21
+ "webpack": "^1.12.14"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
package/.idea/misc.xml DELETED
@@ -1,4 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager" version="2" />
4
- </project>