Skip to content

Commit ea190aa

Browse files
committed
3.0.0
1 parent 597ea51 commit ea190aa

25 files changed

+4411
-5998
lines changed

.eslintrc.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ module.exports = {
66
env: {
77
node: true,
88
es6: true,
9-
jest: true
9+
jest: true,
1010
},
1111
parserOptions: {
12-
ecmaVersion: 2017
12+
ecmaVersion: 2021,
1313
},
1414
rules: {
15-
"no-unused-vars": "warn"
16-
}
15+
"no-unused-vars": "warn",
16+
},
1717
};

.github/workflows/nodejs.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Code quality
2+
3+
on:
4+
push:
5+
paths:
6+
- ".github/**"
7+
- "yarn.lock"
8+
- "**.js"
9+
10+
jobs:
11+
test_and_lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- uses: actions/cache@master
17+
id: node_modules_cache
18+
with:
19+
path: node_modules
20+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
21+
22+
- run: yarn install --frozen-lockfile
23+
if: steps.node_modules_cache.outputs.cache-hit != 'true'
24+
25+
- run: yarn e2e

.travis.yml

-9
This file was deleted.

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 3.0.0
6+
7+
- Drop support node v8
8+
- Update `loader-utils` to the latest version
9+
- Update webpack peer dependencies limit (thanks [@daniele-orlando][https://github.com/daniele-orlando] [#15](https://github.com/retyui/clean-css-loader/issues/15))
10+
- Update dev dependency
11+
- Update webpack e2e tests from `webpack@4` => `webpack@5`
12+
513
## 2.0.0
614

715
- Drop support node v6

README.md

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<div align="center">
2-
<img src="https://cdn.rawgit.com/jakubpawlowicz/clean-css/master/logo.v2.svg" alt="clean-css logo" width="500"/>
2+
<img src="https://cdn.rawgit.com/jakubpawlowicz/clean-css/master/logo.v2.svg" alt="clean-css logo" width="400"/>
33
<br>
44
<a href="https://github.com/webpack/webpack">
5-
<img width="200" height="200"
6-
src="https://webpack.js.org/assets/icon-square-big.svg">
5+
<img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg">
76
</a>
87
</div>
98

@@ -31,32 +30,35 @@ Use the loader either via your webpack config, CLI or inline.
3130
**webpack.config.js**
3231

3332
```js
34-
const production = false;
33+
const isProductionMode = process.env.NODE_ENV === "production";
3534

36-
const cssUseList = ["style-loader", "css-loader"];
35+
const cssLoaders = ["style-loader", "css-loader"];
3736

38-
if (production) {
39-
cssUseList.push("clean-css-loader");
40-
// or with options
41-
cssUseList.push({
37+
if (isProductionMode) {
38+
// push loader for production mode only
39+
cssLoaders.push("clean-css-loader");
40+
41+
// exmaple with options
42+
cssLoaders.push({
4243
loader: "clean-css-loader",
4344
options: {
4445
compatibility: "ie9",
4546
level: 2,
46-
inline: ["remote"]
47-
}
47+
inline: ["remote"],
48+
},
4849
});
4950
}
5051

5152
module.exports = {
53+
mode: isProductionMode ? "production" : "development",
5254
module: {
5355
rules: [
5456
{
5557
test: /\.css$/,
56-
use: cssUseList
57-
}
58-
]
59-
}
58+
use: cssLoaders,
59+
},
60+
],
61+
},
6062
};
6163
```
6264

@@ -104,19 +106,19 @@ module.exports = {
104106
loaders: [
105107
{
106108
test: /\.css$/,
107-
loader: "css!clean-css"
109+
loader: "css!clean-css",
108110
},
109111
{
110112
test: /\.styl$/,
111-
loader: "css!clean-css!stylus?reslve url"
112-
}
113+
loader: "css!clean-css!stylus?reslve url",
114+
},
113115
//...
114116
],
115117
// Example Set options (Key "clean-css" or cleancss or CleanCSS):
116118
"clean-css": {
117119
debug: true,
118-
mediaMerging: true
119-
}
120-
}
120+
mediaMerging: true,
121+
},
122+
},
121123
};
122124
```

appveyor.yml

-21
This file was deleted.

babel.config.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
module.exports = {
2-
presets: [
3-
[
4-
"@babel/preset-env",
5-
{
6-
targets: {
7-
node: "8.9.0"
8-
}
9-
}
10-
]
11-
],
12-
plugins: ["babel-plugin-add-module-exports"]
2+
presets: [["@babel/preset-env", { targets: { node: "10.13.0" } }]],
3+
plugins: ["babel-plugin-add-module-exports"],
134
};

lint-staged.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
linters: {
33
"./**/*.js": ["prettier", "eslint --fix", "git add"],
4-
"./**/*.css": ["prettier", "git add"]
4+
"./**/*.css": ["prettier", "git add"],
55
},
6-
ignore: ["test/e2e/**/*.test.js"]
6+
ignore: ["test/e2e/**/*.test.js"],
77
};

package.json

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "clean-css-loader",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"main": "lib/index.js",
55
"dependencies": {
6-
"clean-css": "^4.2.1",
7-
"loader-utils": "^1.2.3"
6+
"clean-css": "^4.2.3",
7+
"loader-utils": "^2.0.0"
88
},
99
"peerDependencies": {
10-
"webpack": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0"
10+
"webpack": ">=1.0.0"
1111
},
1212
"scripts": {
1313
"e2e": "yarn build && yarn update-e2e && yarn test",
1414
"force-clean": "rimraf ./test/e2e/webpack*/node_modules/ ./test/e2e/webpack*/tests/**/*.test.js",
15-
"install-sub": "yarn link && cd ./test/e2e/webpack1 && yarn && yarn link clean-css-loader && yarn build && cd ../webpack4 && yarn && yarn link clean-css-loader && yarn build && cd ../../..",
15+
"install-sub": "yarn link && cd ./test/e2e/webpack1 && yarn && yarn link clean-css-loader && yarn build && cd ../webpack5 && yarn && yarn link clean-css-loader && yarn build && cd ../../..",
1616
"update-e2e": "yarn force-clean && yarn install-sub",
1717
"prebuild": "rimraf ./lib",
1818
"build": "babel src --out-dir lib",
@@ -33,25 +33,25 @@
3333
"lib"
3434
],
3535
"engines": {
36-
"node": ">=8.0.0"
36+
"node": ">= 10.13.0"
3737
},
3838
"devDependencies": {
39-
"@babel/cli": "^7.4.4",
40-
"@babel/core": "^7.4.4",
41-
"@babel/preset-env": "^7.4.4",
42-
"babel-eslint": "^10.0.1",
43-
"babel-jest": "^24.8.0",
44-
"babel-plugin-add-module-exports": "^1.0.2",
45-
"eslint": "^5.16.0",
46-
"eslint-config-prettier": "^4.2.0",
39+
"@babel/cli": "^7.12.10",
40+
"@babel/core": "^7.12.10",
41+
"@babel/preset-env": "^7.12.11",
42+
"babel-eslint": "^10.1.0",
43+
"babel-jest": "^26.6.3",
44+
"babel-plugin-add-module-exports": "^1.0.4",
45+
"eslint": "^7.18.0",
46+
"eslint-config-prettier": "^7.2.0",
4747
"eslint-config-webpack": "^1.2.5",
48-
"eslint-plugin-import": "^2.17.2",
49-
"eslint-plugin-prettier": "^3.0.1",
50-
"husky": "^2.2.0",
51-
"jest": "^24.8.0",
52-
"lint-staged": "^8.1.6",
48+
"eslint-plugin-import": "^2.22.1",
49+
"eslint-plugin-prettier": "^3.3.1",
50+
"husky": "^4.3.8",
51+
"jest": "^26.6.3",
52+
"lint-staged": "^10.5.3",
5353
"npm-run-all": "^4.1.5",
54-
"prettier": "^1.17.0",
55-
"rimraf": "^2.6.3"
54+
"prettier": "^2.2.1",
55+
"rimraf": "^3.0.2"
5656
}
5757
}

prettier.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
printWidth: 80,
3-
useTabs: true,
4-
tabWidth: 2
3+
useTabs: false,
4+
tabWidth: 2,
55
};

src/index.js

+33-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
import CleanCSS from "clean-css";
22
import { getOptions } from "loader-utils";
33

4-
export default function cleanCssLoader(css, map) {
5-
const options = this.options ? this.options.module : false;
6-
const query = getOptions(this);
7-
const cleanCssOptions =
8-
query ||
9-
(options
10-
? options.cleancss || options["clean-css"] || options.CleanCSS
11-
: false) ||
12-
{};
13-
const callback = this.async();
14-
15-
return new CleanCSS(cleanCssOptions).minify(css, map, (err, minified) => {
16-
if (err) {
17-
return callback(err[0]);
18-
}
19-
20-
if (!cleanCssOptions.skipWarn && Array.isArray(minified.warnings)) {
21-
minified.warnings.forEach(warning => {
22-
this.emitWarning(warning.toString());
23-
});
24-
}
25-
26-
return callback(null, minified.styles, minified.sourceMap);
27-
});
4+
function getCleanCssOptions({ query, options }) {
5+
if (query && Object.keys(query).length > 0) {
6+
return query;
7+
}
8+
9+
const legacyOptionsSyntax =
10+
options && (options.cleancss || options["clean-css"] || options.CleanCSS);
11+
12+
return legacyOptionsSyntax || {};
13+
}
14+
15+
function cleanCssLoader(css, map) {
16+
const callback = this.async();
17+
const cleanCssOptions = getCleanCssOptions({
18+
query: getOptions(this),
19+
options: this.options ? this.options.module : false,
20+
});
21+
22+
return new CleanCSS(cleanCssOptions).minify(css, map, (err, minified) => {
23+
if (err) {
24+
return callback(err[0]);
25+
}
26+
27+
if (!cleanCssOptions.skipWarn && Array.isArray(minified.warnings)) {
28+
minified.warnings.forEach((warning) => {
29+
this.emitWarning(warning.toString());
30+
});
31+
}
32+
33+
return callback(null, minified.styles, minified.sourceMap);
34+
});
2835
}
36+
37+
export default cleanCssLoader;

0 commit comments

Comments
 (0)