Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/make-postcss.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
let path = require("path");
let postcss = require("postcss");
let atImport = require("postcss-import");
let postcssPresetEnv = require("postcss-preset-env");
let assetURL = require("./asset-url");
let { promisify } = require("faucet-pipeline-core/lib/util");
let { repr, promisify } = require("faucet-pipeline-core/lib/util");
let readFile = promisify(require("fs").readFile);

module.exports = function(input, target, assetManager, sourcemaps, browsers, compact) {
Expand All @@ -17,6 +19,18 @@ module.exports = function(input, target, assetManager, sourcemaps, browsers, com
);
}

if(browsers && browsers.length > 0) {
let filepath = path.relative(assetManager.referenceDir, input);
console.error(`compiling CSS ${repr(filepath)} for ${browsers.join(", ")}`);
plugins.push(postcssPresetEnv({
stage: 2, // maybe a little too unstable?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the CSS process, but the JavaScript experience suggests that combining volatile (i.e. not-yet-finalized) features in a single package/declaration/whatever is bound to be troublesome:
https://babeljs.io/blog/2018/07/27/removing-babels-stage-presets
(TLDR: What's stage 2 today might be different next month, both in terms of the set of features and their respective contracts. Thus volatile features need to be versioned independently.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm discussing this in the above linked issue. I'm not sure what is the best approach yet. But I'm not sure it makes sense to choose features by their stage 🤔

browsers: browsers,
autoprefixer: {
cascade: false // this disables weird indentation
}
}));
}

let processor = postcss(plugins);

let options = {
Expand Down
5 changes: 5 additions & 0 deletions test/run
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ begin "$root/test_static_integration"
assert_identical "./dist/bundle.css" "./expected.css"
end

begin "$root/test_cssnext"
faucet
assert_identical "./dist/bundle.css" "./expected.css"
end

echo; echo "SUCCESS: all tests passed"
1 change: 1 addition & 0 deletions test/test_cssnext/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IE 10
11 changes: 11 additions & 0 deletions test/test_cssnext/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:root {
--fontSize: 1rem;
}

body {
font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
font-size: 1rem;
font-size: var(--fontSize);
-ms-user-select: none;
user-select: none;
}
15 changes: 15 additions & 0 deletions test/test_cssnext/faucet.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";
let path = require("path");

module.exports = {
css: [{
source: "./src/index.css",
target: "./dist/bundle.css"
}],
plugins: {
css: {
plugin: path.resolve("../.."),
bucket: "styles"
}
}
};
9 changes: 9 additions & 0 deletions test/test_cssnext/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
:root {
--fontSize: 1rem;
}

body {
font-family: system-ui;
font-size: var(--fontSize);
user-select: none;
}