Skip to content

Commit 7592e26

Browse files
committed
Merge pull request MoOx#264 from rafaelrinaldi/fix/pixrem-browsers-list
Added: Pass in `browsers` options to pixrem
2 parents 1a62f04 + 0fb0942 commit 7592e26

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/__tests__/option.browsers.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tape("cssnext browsers option", function(t) {
4040
t.end()
4141
})
4242

43-
tape("cssnext browsers option propagation", function(t) {
43+
tape("cssnext browsers option propagation to autoprefixer", function(t) {
4444
const input = "body{transition: 1s}"
4545
const output = "body{-webkit-transition: 1s;transition: 1s}"
4646

@@ -60,3 +60,17 @@ tape("cssnext browsers option propagation", function(t) {
6060

6161
t.end()
6262
})
63+
64+
tape("cssnext browsers option propagation to pixrem", function(t) {
65+
const input = "body{font-size: 1rem}"
66+
const output = "body{font-size: 16px;font-size: 1rem}"
67+
68+
// IE 8 needs rem fallback
69+
t.equal(
70+
cssnext({ browsers: "ie 8" }).process(input).css,
71+
output,
72+
"should propagate browsers option to pixrem"
73+
)
74+
75+
t.end()
76+
})

src/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,25 @@ const plugin = postcss.plugin("postcss-cssnext", (options) => {
1414

1515
const features = options.features
1616

17-
// propagate browsers option to autoprefixer
18-
if (features.autoprefixer !== false) {
19-
features.autoprefixer = {
20-
browsers: (
21-
features.autoprefixer && features.autoprefixer.browsers
22-
? features.autoprefixer.browsers
23-
: options.browsers
24-
),
25-
...(features.autoprefixer || {}),
26-
}
17+
// propagate browsers option to plugins that supports it
18+
"autoprefixer pixrem".split(/\s/).forEach(name => {
19+
const feature = features[name]
2720

28-
// autoprefixer doesn't like an "undefined" value. Related to coffee ?
29-
if (features.autoprefixer.browsers === undefined) {
30-
delete features.autoprefixer.browsers
21+
if (feature !== false) {
22+
features[name] = {
23+
browsers: (
24+
feature && feature.browsers
25+
? feature.browsers
26+
: options.browsers
27+
),
28+
...(feature || {}),
29+
}
3130
}
31+
})
32+
33+
// autoprefixer doesn't like an "undefined" value. Related to coffee ?
34+
if (features.autoprefixer && features.autoprefixer.browsers === undefined) {
35+
delete features.autoprefixer.browsers
3236
}
3337

3438
const processor = postcss()

0 commit comments

Comments
 (0)