Skip to content

Commit 63a86f0

Browse files
authored
Merge pull request #153 from webpack-contrib/maintenance
Maintenance
2 parents c9f6f94 + 144798f commit 63a86f0

File tree

144 files changed

+529
-6770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+529
-6770
lines changed

.editorconfig

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
# EditorConfig is awesome: http://EditorConfig.org
1+
# This file is for unifying the coding style for different editors and IDEs.
2+
# More information at http://EditorConfig.org
23

3-
# top-most EditorConfig file
4+
# No .editorconfig files above the root directory
45
root = true
56

6-
# Unix-style newlines with a newline ending every file
77
[*]
8+
indent_style = space
9+
indent_size = 4
810
charset = utf-8
9-
end_of_line = lf
11+
trim_trailing_whitespace = true
1012
insert_final_newline = true
11-
indent_style = tab
12-
indent_size = 4
1313

14-
# Matches the exact files either package.json or .travis.yml
15-
[{package.json,.travis.yml}]
16-
indent_style = space
14+
[package.json]
1715
indent_size = 2

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Compiled by webpack
2+
test/output
3+
4+
# Fake node_modules folder for tests
5+
test/node_modules

.eslintrc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": [
3+
"peerigon/base"
4+
],
5+
"env": {
6+
"node": true
7+
},
8+
"root": true
9+
}

.gitignore

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
npm-debug.log
115
/node_modules
2-
test/node_modules/*
3-
test/output/*
16+
coverage
17+
.idea
18+
.nyc_output
19+
test/output

.jshintrc

Lines changed: 0 additions & 48 deletions
This file was deleted.

.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.nycrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"reporter": [
3+
"lcov",
4+
"text"
5+
],
6+
"include": [
7+
"lib/**/*.js"
8+
],
9+
"lines": 92,
10+
"statements": 92,
11+
"functions": 100,
12+
"branches": 70,
13+
"check-coverage": true
14+
}

README.md

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[![npm][npm]][npm-url]
22
[![node][node]][node-url]
3+
[![npm-stats][npm-stats]][npm-url]
34
[![deps][deps]][deps-url]
4-
[![tests][tests]][tests-url]
5+
[![travis][travis]][travis-url]
6+
[![appveyor][appveyor]][appveyor-url]
57
[![coverage][cover]][cover-url]
68
[![chat][chat]][chat-url]
79

@@ -31,7 +33,7 @@ Chain the less-loader with the [css-loader](https://github.com/webpack-contrib/c
3133
```js
3234
// webpack.config.js
3335
module.exports = {
34-
...
36+
...
3537
module: {
3638
rules: [{
3739
test: /\.less$/,
@@ -47,14 +49,12 @@ module.exports = {
4749
};
4850
```
4951

50-
<h2 align="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:
5353

5454
```js
5555
// webpack.config.js
5656
module.exports = {
57-
...
57+
...
5858
module: {
5959
rules: [{
6060
test: /\.less$/,
@@ -73,6 +73,54 @@ module.exports = {
7373
};
7474
```
7575

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:
79+
80+
```js
81+
const ExtractTextPlugin = require("extract-text-webpack-plugin");
82+
83+
const extractLess = new ExtractTextPlugin({
84+
filename: "[name].[contenthash].css",
85+
disable: process.env.NODE_ENV === "development"
86+
});
87+
88+
module.exports = {
89+
...
90+
module: {
91+
rules: [{
92+
test: /\.less$/,
93+
loader: extractLess.extract({
94+
use: [{
95+
loader: "css-loader"
96+
}, {
97+
loader: "less-loader"
98+
}],
99+
// use style-loader in development
100+
fallback: "style-loader"
101+
})
102+
}]
103+
},
104+
plugins: [
105+
extractLess
106+
]
107+
};
108+
```
109+
110+
<h2 align="center">Usage</h2>
111+
112+
### Imports
113+
114+
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+
76124
### Plugins
77125

78126
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
82130
const CleanCSSPlugin = require("less-plugin-clean-css");
83131

84132
module.exports = {
85-
...
133+
...
86134
{
87135
loader: "less-loader", options: {
88136
lessPlugins: [
@@ -94,17 +142,14 @@ module.exports = {
94142
};
95143
```
96144

97-
### Imports
145+
### Extracting style sheets
98146

99-
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.
104148

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:
106150

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)
108153

109154
### Source maps
110155

@@ -157,6 +202,7 @@ The tests are basically just comparing the generated css with a reference css-fi
157202

158203

159204
[npm]: https://img.shields.io/npm/v/less-loader.svg
205+
[npm-stats]: https://img.shields.io/npm/dm/less-loader.svg
160206
[npm-url]: https://npmjs.com/package/less-loader
161207

162208
[node]: https://img.shields.io/node/v/less-loader.svg
@@ -165,8 +211,11 @@ The tests are basically just comparing the generated css with a reference css-fi
165211
[deps]: https://david-dm.org/webpack-contrib/less-loader.svg
166212
[deps-url]: https://david-dm.org/webpack-contrib/less-loader
167213

168-
[tests]: http://img.shields.io/travis/webpack-contrib/less-loader.svg
169-
[tests-url]: https://travis-ci.org/webpack-contrib/less-loader
214+
[travis]: http://img.shields.io/travis/webpack-contrib/less-loader.svg
215+
[travis-url]: https://travis-ci.org/webpack-contrib/less-loader
216+
217+
[appveyor-url]: https://ci.appveyor.com/project/jhnns/less-loader/branch/master
218+
[appveyor]: https://ci.appveyor.com/api/projects/status/github/webpack-contrib/less-loader?svg=true
170219

171220
[cover]: https://coveralls.io/repos/github/webpack-contrib/less-loader/badge.svg
172221
[cover-url]: https://coveralls.io/github/webpack-contrib/less-loader

appveyor.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# appveyor file
2+
# http://www.appveyor.com/docs/appveyor-yml
3+
4+
init:
5+
- git config --global core.autocrlf input
6+
7+
# what combinations to test
8+
environment:
9+
matrix:
10+
- nodejs_version: 7
11+
job_part: test
12+
- nodejs_version: 6
13+
job_part: test
14+
- nodejs_version: 4
15+
job_part: test
16+
17+
install:
18+
- ps: Install-Product node $env:nodejs_version x64
19+
- npm install
20+
21+
build: off
22+
23+
matrix:
24+
fast_finish: true
25+
26+
test_script:
27+
- node --version
28+
- npm --version
29+
- cmd: npm run appveyor:%job_part%

0 commit comments

Comments
 (0)