You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+66-17Lines changed: 66 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,9 @@
1
1
[![npm][npm]][npm-url]
2
2
[![node][node]][node-url]
3
+
[![npm-stats][npm-stats]][npm-url]
3
4
[![deps][deps]][deps-url]
4
-
[![tests][tests]][tests-url]
5
+
[![travis][travis]][travis-url]
6
+
[![appveyor][appveyor]][appveyor-url]
5
7
[![coverage][cover]][cover-url]
6
8
[![chat][chat]][chat-url]
7
9
@@ -31,7 +33,7 @@ Chain the less-loader with the [css-loader](https://github.com/webpack-contrib/c
31
33
```js
32
34
// webpack.config.js
33
35
module.exports= {
34
-
...
36
+
...
35
37
module: {
36
38
rules: [{
37
39
test:/\.less$/,
@@ -47,14 +49,12 @@ module.exports = {
47
49
};
48
50
```
49
51
50
-
<h2align="center">Options</h2>
51
-
52
-
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.
52
+
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:
53
53
54
54
```js
55
55
// webpack.config.js
56
56
module.exports= {
57
-
...
57
+
...
58
58
module: {
59
59
rules: [{
60
60
test:/\.less$/,
@@ -73,6 +73,54 @@ module.exports = {
73
73
};
74
74
```
75
75
76
+
### In production
77
+
78
+
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:
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 resolving engine. 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).
115
+
116
+
```css
117
+
@import"~bootstrap/less/bootstrap";
118
+
```
119
+
120
+
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";`
121
+
122
+
Also please note that for [CSS modules](https://github.com/css-modules/css-modules), relative file paths do not work as expected. Please see [this issue for the explanation](https://github.com/webpack-contrib/less-loader/issues/109#issuecomment-253797335).
123
+
76
124
### Plugins
77
125
78
126
In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the `lessPlugins` option like this:
@@ -82,7 +130,7 @@ In order to use [plugins](http://lesscss.org/usage/#plugins), simply set the `le
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 resolving engine. 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).
100
-
101
-
```css
102
-
@import"~bootstrap/less/bootstrap";
103
-
```
147
+
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.
104
148
105
-
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";`
149
+
There are two possibilities to extract a style sheet from the bundle:
106
150
107
-
Also please note that for [CSS modules](https://github.com/css-modules/css-modules), relative file paths do not work as expected. Please see [this issue for the explanation](https://github.com/webpack-contrib/less-loader/issues/109#issuecomment-253797335).
151
+
-[extract-loader](https://github.com/peerigon/extract-loader) (simpler, but specialized on the css-loader's output)
152
+
-[extract-text-webpack-plugin](https://github.com/webpack-contrib/extract-text-webpack-plugin) (more complex, but works in all use-cases)
108
153
109
154
### Source maps
110
155
@@ -157,6 +202,7 @@ The tests are basically just comparing the generated css with a reference css-fi
0 commit comments