Skip to content

Commit 677a416

Browse files
committed
Use cssnano for removing whitespace
1 parent 5a269a8 commit 677a416

File tree

5 files changed

+47
-56
lines changed

5 files changed

+47
-56
lines changed

gulpfile.js

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

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222
"bluebird": "^3.5.0",
2323
"chai": "^4.1.1",
2424
"chai-as-promised": "^7.1.1",
25-
"clean-css": "^4.1.7",
25+
"cssnano": "^4.0.0",
2626
"eslint": "^4.4.1",
2727
"eslint-plugin-react": "^7.1.0",
28-
"gulp": "^3.8.11",
29-
"gulp-eslint": "^4.0.0",
30-
"gulp-mocha": "^4.3.1",
31-
"mocha": "^3.5.0"
28+
"mocha": "^3.5.0",
29+
"postcss-normalize-whitespace": "^4.0.0"
3230
},
3331
"scripts": {
34-
"test": "gulp",
32+
"test": "mocha",
3533
"lint": "eslint ."
3634
}
3735
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
:root {
2-
--width: 100px;
2+
--width: 100px;
33
}
44

55
@media (max-width: 1000px) {
6-
:root {
7-
--width: 200px;
8-
}
6+
:root {
7+
--width: 200px;
8+
}
99
}
1010

1111
.box {
12-
width: var(--width);
12+
width: var(--width);
1313
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
:root {
2-
--width: 100px;
2+
--width: 100px;
33
}
44

55
@media (max-width: 1000px) {
6-
:root {
7-
--width: 200px;
8-
}
6+
:root {
7+
--width: 200px;
8+
}
99
}
1010

1111
.box {
12-
width: 100px;
13-
width: var(--width);
12+
width: 100px;
13+
width: var(--width);
1414
}
1515

1616
@media (max-width: 1000px) {
17-
18-
.box {
19-
width: 200px;
20-
width: var(--width);
21-
}
17+
.box {
18+
width: 200px;
19+
width: var(--width);
20+
}
2221
}

test/test.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ chai.use(chaiAsPromised);
99

1010
var postcss = require('postcss');
1111
var cssvariables = require('../');
12-
13-
var CleanCSS = require('clean-css');
12+
var cssnano = require('cssnano');
13+
var normalizeWhitespace = require('postcss-normalize-whitespace');
1414

1515
var MOCK_JS_VARIABLES = {
1616
'--js-defined1': '75px',
@@ -23,31 +23,33 @@ var MOCK_JS_VARIABLES = {
2323

2424
var testPlugin = function(filePath, expectedFilePath, options) {
2525
options = options || {};
26-
return fs.readFileAsync(filePath)
27-
.then(function(buffer) {
28-
var contents = String(buffer);
29-
var actual = postcss(cssvariables(options)).process(contents);
30-
31-
return actual.css;
26+
return Promise.props({
27+
actualBuffer: fs.readFileAsync(filePath),
28+
expectedBuffer: fs.readFileAsync(expectedFilePath)
29+
})
30+
.then(function({ actualBuffer, expectedBuffer }) {
31+
var actualResult = postcss([
32+
cssvariables(options),
33+
cssnano({
34+
preset: { plugins: [normalizeWhitespace] }
35+
})
36+
])
37+
.process(String(actualBuffer));
38+
39+
var expectedResult = postcss([
40+
cssnano({
41+
preset: { plugins: [normalizeWhitespace] }
42+
})
43+
])
44+
.process(String(expectedBuffer));
45+
46+
return Promise.props({
47+
actualResult: actualResult,
48+
expectedResult: expectedResult
49+
});
3250
})
33-
.then(function(actual) {
34-
return fs.readFileAsync(expectedFilePath)
35-
.then(function(buffer) {
36-
var contents = String(buffer);
37-
38-
var cleanCss = new CleanCSS({
39-
advanced: false,
40-
aggressiveMerging: false,
41-
mediaMerging: false,
42-
restructuring: false,
43-
shorthandCompacting: false,
44-
//keepBreaks: true,
45-
compatibility: '-properties.merging'
46-
});
47-
48-
expect(cleanCss.minify(actual).styles).to.equal(cleanCss.minify(contents).styles);
49-
//expect(actual).to.equal(contents);
50-
});
51+
.then(({ actualResult, expectedResult }) => {
52+
expect(actualResult.css.replace(/\r?\n/g, '')).to.equal(expectedResult.css.replace(/\r?\n/g, ''));
5153
});
5254
};
5355

0 commit comments

Comments
 (0)