Skip to content

Commit ab0b292

Browse files
author
♥ David ♥
committed
1 parent 40a03c1 commit ab0b292

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
A [clean-css](https://github.com/jakubpawlowicz/clean-css) loader for [webpack](https://github.com/webpack/webpack).
2+
3+
[![npm version](https://badge.fury.io/js/clean-css-loader.svg)](https://badge.fury.io/js/clean-css-loader)
4+
5+
6+
**Example config:**
7+
8+
```js
9+
...
10+
module: {
11+
loaders: [
12+
{
13+
test: /\.css$/,
14+
loader: 'css!clean-css'
15+
},
16+
{
17+
test: /\.styl$/,
18+
loader: 'css!clean-css!stylus?reslve url'
19+
}
20+
...
21+
]
22+
// Example Set options (Key "clean-css" or cleancss or CleanCSS):
23+
"clean-css":{
24+
debug:true,
25+
mediaMerging: true
26+
}
27+
}
28+
```
29+
More option: [https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api](https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api)
30+

index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@ var CleanCSS = require('clean-css');
44

55
module.exports = function (css, map) {
66

7-
var opti = this.options;
7+
var opti = this.options.module;
88
var cleanCssOpti = opti.cleancss || opti['clean-css'] || opti.CleanCSS || {};
9+
var loader = this;
910
var callback = this.async();
1011

1112
new CleanCSS(cleanCssOpti).minify(css, function (err, minified) {
12-
if ( err ) { return callback(err);}
13+
if ( err ) {
14+
if (Array.isArray(err) && (arr[0] != null)) {
15+
return callback(err[0]);
16+
}else{
17+
return callback(err);
18+
}
19+
}
20+
var ref;
21+
if (((ref = minified.warnings) != null ? ref.lenght : void 0) !== 0) {
22+
ref.forEach(function (msg) {
23+
loader.emitWarning(msg.toString());
24+
});
25+
}
1326
// minified.styles
1427
return callback(null, minified.styles, minified.sourceMap);
1528
});

0 commit comments

Comments
 (0)