Skip to content

Commit 831eeb4

Browse files
committed
Add typescript (#18)
Signed-off-by: David <4661784+retyui@users.noreply.github.com>
1 parent d55e0d4 commit 831eeb4

23 files changed

+1589
-5769
lines changed

.eslintrc.js

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

.github/workflows/nodejs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
jobs:
1111
test_and_lint:
1212
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
node: [10, 12, 14, 16]
1316
steps:
1417
- uses: actions/checkout@v2
1518

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
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+
## 4.0.0
6+
7+
- Migrate to the latest [`clean-css`](https://clean-css.github.io/) version `5.x.x`
8+
- Add Schema validation
9+
- Add new option `disable: boolean`
10+
- Drop support `webpack@1.x.x`
11+
- Add Typescript
12+
513
## 3.0.0
614

715
- Drop support node v8

README.md

Lines changed: 39 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -11,114 +11,72 @@ A [clean-css](https://github.com/jakubpawlowicz/clean-css) loader for [webpack](
1111
# clean-css-loader
1212

1313
[![npm](https://img.shields.io/npm/v/clean-css-loader.svg)](https://www.npmjs.com/package/clean-css-loader)
14+
[![CI](https://github.com/retyui/clean-css-loader/actions/workflows/nodejs.yml/badge.svg)](https://github.com/retyui/clean-css-loader/actions/workflows/nodejs.yml)
1415
[![npm clean-css-loader](https://img.shields.io/npm/dm/clean-css-loader.svg)](https://www.npmjs.com/package/clean-css-loader)
15-
[![AppVeyor](https://img.shields.io/appveyor/ci/retyui/clean-css-loader.svg?label=windows)](https://ci.appveyor.com/project/retyui/clean-css-loader)
16-
[![Travis](https://img.shields.io/travis/retyui/clean-css-loader.svg?label=unix)](https://travis-ci.org/retyui/clean-css-loader)
1716

18-
## Install
17+
## Getting Started
18+
19+
To begin, you'll need to install clean-css-loader:
1920

2021
```bash
2122
yarn add -D clean-css-loader
2223
```
2324

24-
## Usage
25-
26-
Use the loader either via your webpack config, CLI or inline.
27-
28-
### Via webpack config (recommended)
29-
30-
**webpack.config.js**
25+
Then add the plugin to your webpack config. For example:
3126

32-
```js
33-
const isProductionMode = process.env.NODE_ENV === "production";
34-
35-
const cssLoaders = ["style-loader", "css-loader"];
36-
37-
if (isProductionMode) {
38-
// push loader for production mode only
39-
cssLoaders.push("clean-css-loader");
40-
41-
// exmaple with options
42-
cssLoaders.push({
43-
loader: "clean-css-loader",
44-
options: {
45-
compatibility: "ie9",
46-
level: 2,
47-
inline: ["remote"],
48-
},
49-
});
50-
}
27+
```tsx
28+
// webpack.config.js
29+
const isProduction = process.env.NODE_ENV === "production";
5130

5231
module.exports = {
53-
mode: isProductionMode ? "production" : "development",
32+
mode: isProduction ? "production" : "development",
5433
module: {
5534
rules: [
5635
{
5736
test: /\.css$/,
58-
use: cssLoaders,
37+
use: [
38+
"style-loader",
39+
"css-loader",
40+
{
41+
loader: "clean-css-loader",
42+
options: {
43+
// Loader options
44+
disable: !isProduction,
45+
skipWarn: false,
46+
47+
// CleasCSS options
48+
compatibility: "ie9",
49+
level: 2,
50+
inline: ["remote"],
51+
//...
52+
},
53+
},
54+
],
5955
},
6056
],
6157
},
6258
};
6359
```
6460

65-
**In your application**
61+
Or using plugin [inline](https://webpack.js.org/concepts/loaders/#inline):
6662

67-
```js
68-
import cssMin from "style.css";
69-
```
70-
71-
### CLI
72-
73-
```bash
74-
webpack --module-bind 'css=style-loader!css-loader!clean-css-loader'
75-
```
76-
77-
**In your application**
78-
79-
```js
80-
import cssMin from "style.css";
81-
```
82-
83-
### Inline
84-
85-
**In your application**
86-
87-
```js
88-
import cssMin from "style-loader!css-loader!clean-css-loader!./style.css";
63+
```tsx
64+
// default
65+
import "style-loader!css-loader!clean-css-loader!./style.css";
66+
// with options
67+
import "style-loader!css-loader!clean-css-loader?level=2!./style.css";
8968
```
9069

9170
## Options
9271

93-
### `skipWarn` default: `false`
72+
#### `disable: boolean`
9473

95-
This option disable output warnings
74+
This option enables/disables minify, useful to easily disable on development mode (default: `false`)
9675

97-
More option: [https://github.com/jakubpawlowicz/clean-css#constructor-options](https://github.com/jakubpawlowicz/clean-css#constructor-options)
76+
#### `skipWarn: boolean`
9877

99-
## Webpack 1.x
78+
This option enables/disables output warnings (default: `false`)
10079

101-
**Example config (for webpack 1.x):**
80+
## `CleanCSS` module options
10281

103-
```js
104-
module.exports = {
105-
module: {
106-
loaders: [
107-
{
108-
test: /\.css$/,
109-
loader: "css!clean-css",
110-
},
111-
{
112-
test: /\.styl$/,
113-
loader: "css!clean-css!stylus?reslve url",
114-
},
115-
//...
116-
],
117-
// Example Set options (Key "clean-css" or cleancss or CleanCSS):
118-
"clean-css": {
119-
debug: true,
120-
mediaMerging: true,
121-
},
122-
},
123-
};
124-
```
82+
- [clean-css/clean-css#constructor-options](https://github.com/jakubpawlowicz/clean-css#constructor-options)

babel.config.js

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

lint-staged.config.js

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

package.json

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
{
22
"name": "clean-css-loader",
3-
"version": "3.0.0",
3+
"version": "4.0.0",
44
"main": "lib/index.js",
5-
"dependencies": {
6-
"clean-css": "^4.2.3",
7-
"loader-utils": "^2.0.0"
5+
"types": "lib/index.d.ts",
6+
"dependencies": {
7+
"clean-css": "^5.0.0"
88
},
99
"peerDependencies": {
10-
"webpack": ">=1.0.0"
10+
"loader-utils": "^1.0.0 || ^2.0.0",
11+
"webpack": ">=2.0.0"
12+
},
13+
"peerDependenciesMeta": {
14+
"webpack": {
15+
"optional": true
16+
},
17+
"loader-utils": {
18+
"optional": true
19+
}
1120
},
1221
"scripts": {
13-
"e2e": "yarn build && yarn update-e2e && yarn test",
22+
"pree2e": "yarn build",
23+
"e2e": "yarn update-e2e && yarn test",
1424
"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 ../webpack5 && yarn && yarn link clean-css-loader && yarn build && cd ../../..",
25+
"install-sub": "yarn link && cd test/e2e/webpack5 && yarn && yarn build && cd ../../..",
1626
"update-e2e": "yarn force-clean && yarn install-sub",
1727
"prebuild": "rimraf ./lib",
18-
"build": "babel src --out-dir lib",
19-
"pretest": "yarn build",
20-
"test": "jest",
21-
"precommit": "lint-staged"
28+
"build": "tsc",
29+
"postbuild": "prettier --write ./lib",
30+
"test": "jest"
2231
},
2332
"description": "CleanCSS loader module for webpack",
2433
"keywords": [
@@ -27,31 +36,24 @@
2736
"loader"
2837
],
2938
"repository": "https://github.com/retyui/clean-css-loader",
30-
"author": "David <vamnemne@gmail.com>",
39+
"author": "David <4661784+retyui@users.noreply.github.com>",
3140
"license": "MIT",
32-
"files": [
33-
"lib"
34-
],
41+
"files": ["lib"],
3542
"engines": {
36-
"node": ">= 10.13.0"
43+
"node": ">= 10.0.0"
3744
},
3845
"devDependencies": {
39-
"@babel/cli": "^7.15.4",
40-
"@babel/core": "^7.15.5",
41-
"@babel/preset-env": "^7.15.4",
42-
"babel-eslint": "^10.1.0",
43-
"babel-jest": "^27.1.0",
44-
"babel-plugin-add-module-exports": "^1.0.4",
45-
"eslint": "^7.32.0",
46-
"eslint-config-prettier": "^8.3.0",
47-
"eslint-config-webpack": "^1.2.5",
48-
"eslint-plugin-import": "^2.24.2",
49-
"eslint-plugin-prettier": "^4.0.0",
50-
"husky": "^7.0.2",
46+
"@tsconfig/node10": "^1.0.8",
47+
"@types/clean-css": "^4.2.5",
48+
"@types/loader-utils": "^2.0.3",
49+
"@types/node": "^16.9.6",
50+
"@types/schema-utils": "^2.4.0",
5151
"jest": "^27.1.0",
52-
"lint-staged": "^11.1.2",
53-
"npm-run-all": "^4.1.5",
54-
"prettier": "^2.3.2",
55-
"rimraf": "^3.0.2"
52+
"loader-utils": "^2.0.0",
53+
"prettier": "^2.4.1",
54+
"rimraf": "^3.0.2",
55+
"schema-utils": "^3.1.1",
56+
"typescript": "^4.4.3",
57+
"webpack": "^5.53.0"
5658
}
5759
}

src/index.js

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

0 commit comments

Comments
 (0)