Skip to content

Commit c32c5ed

Browse files
committed
Update README
- Added chapter about source maps - Small clarifications
1 parent c74438f commit c32c5ed

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

README.md

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
loaders: [
2626
{
2727
test: /\.less$/,
28-
loader: "style-loader!css-loader!less-loader"
28+
loader: "style!css!less"
2929
}
3030
]
3131
}
@@ -34,28 +34,24 @@ module.exports = {
3434

3535
Then you only need to write: `require("./file.less")`
3636

37-
### webpack config options
37+
### LESS options
3838

39-
You can pass LESS specific configuration options through to the render function via loader
40-
parameters.
41-
42-
Acceptable config options that can be appended to the loader as parameters are:
43-
44-
paths, optimization, filename, strictImports, syncImport, dumpLineNumbers, relativeUrls, rootpath, compress, cleancss, cleancssOptions, ieCompat, strictMath, strictUnits, urlArgs, sourceMap, sourceMapFilename, sourceMapURL, sourceMapBasepath, sourceMapRootpath, outputSourceFiles'
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).
4540

4641
``` javascript
4742
module.exports = {
4843
module: {
4944
loaders: [
5045
{
5146
test: /\.less$/,
52-
loader: "style-loader!css-loader!less-loader?strictMath&cleancss"
47+
loader: "style!css!less?strictMath&noIeCompat"
5348
}
5449
]
5550
}
5651
};
57-
```
58-
52+
```
53+
54+
See the [LESS documentation](http://lesscss.org/usage/#command-line-usage-options) for all available options. LESS translates dash-case to camelCase.
5955

6056
## Note on imports
6157

@@ -75,7 +71,41 @@ is the same as
7571

7672
```css
7773
@import "./file";
78-
```
74+
```
75+
76+
## Source maps
77+
78+
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).
79+
80+
Then your `webpack.config.js` should look like this:
81+
82+
```javascript
83+
var ExtractTextPlugin = require('extract-text-webpack-plugin');
84+
85+
module.exports = {
86+
...
87+
// must be 'source-map' or 'inline-source-map'
88+
devtool: 'source-map',
89+
module: {
90+
loaders: [
91+
{
92+
test: /\.less$/,
93+
loader: ExtractTextPlugin.extract(
94+
// activate source maps via loader query
95+
'css?sourceMap!' +
96+
'less?sourceMap'
97+
)
98+
}
99+
]
100+
},
101+
plugins: [
102+
// extract inline css into separate 'styles.css'
103+
new ExtractTextPlugin('styles.css')
104+
]
105+
};
106+
```
107+
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.
79109

80110
## Contribution
81111

0 commit comments

Comments
 (0)