Skip to content

Commit 3d442f7

Browse files
committed
Support for compaction, closes #2
1 parent 3eea06d commit 3d442f7

File tree

8 files changed

+46
-5
lines changed

8 files changed

+46
-5
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function makeBundler(config, assetManager, { browsers, compact, sourcemaps } = {
2727
browsers = browsers.defaults;
2828
}
2929

30-
let postCSS = makePostCSS(source, target, assetManager, sourcemaps, browsers);
30+
let postCSS = makePostCSS(source, target, assetManager, sourcemaps, browsers, compact);
3131

3232
let previouslyIncludedFiles;
3333

lib/make-postcss.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@ let atImport = require("postcss-import");
33
let { promisify } = require("faucet-pipeline-core/lib/util");
44
let readFile = promisify(require("fs").readFile);
55

6-
module.exports = function(input, target, assetManager, sourcemaps, browsers) {
6+
module.exports = function(input, target, assetManager, sourcemaps, browsers, compact) {
77
// if(browsers && browsers.length > 0) {
88
// let filepath = path.relative(assetManager.referenceDir, input);
99
// console.error(`compiling CSS ${repr(filepath)} for ${browsers.join(", ")}`);
1010

11-
let processor = postcss([
11+
let plugins = [
1212
atImport()
13-
]);
13+
];
14+
15+
if(compact) {
16+
plugins.push(
17+
require("postcss-discard-comments")(),
18+
require("postcss-normalize-whitespace")()
19+
);
20+
}
21+
22+
let processor = postcss(plugins);
1423

1524
let options = {
1625
from: input,

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"dependencies": {
2222
"faucet-pipeline-core": "^1.0.0",
2323
"postcss": "~7.0.13",
24-
"postcss-import": "~12.0.1"
24+
"postcss-discard-comments": "~4.0.1",
25+
"postcss-import": "~12.0.1",
26+
"postcss-normalize-whitespace": "~4.0.1"
2527
},
2628
"devDependencies": {
2729
"eslint-config-fnd": "^1.6.0",

test/run

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ begin "$root/test_basic"
1212
assert_missing "./expected.json"
1313
end
1414

15+
begin "$root/test_compact"
16+
faucet --compact
17+
assert_identical "./dist/bundle.css" "./expected.css"
18+
end
19+
1520
begin "$root/test_error"
1621
faucet || echo "Crashed successfully"
1722
assert_identical "./dist/bundle.css" "./expected.css"

test/test_compact/expected.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.bar{color:red}.foo{color:green}

test/test_compact/faucet.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
let path = require("path");
3+
4+
module.exports = {
5+
css: [{
6+
source: "./src/index.css",
7+
target: "./dist/bundle.css"
8+
}],
9+
plugins: {
10+
css: {
11+
plugin: path.resolve("../.."),
12+
bucket: "styles"
13+
}
14+
}
15+
};

test/test_compact/src/index.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import "./lib.css";
2+
3+
/* a comment */
4+
.foo {
5+
color: green;
6+
}

test/test_compact/src/lib.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.bar {
2+
color: red;
3+
}

0 commit comments

Comments
 (0)