Skip to content

Commit

Permalink
Remove matching AtRules
Browse files Browse the repository at this point in the history
Use `walkAtRules` to check for matches to things like `@font-face`,
`@charset`, etc.

Closes #9
  • Loading branch information
mewdriller authored and AoDev committed Feb 22, 2017
1 parent 14b8b37 commit 0badb2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/css-byebye.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ var cssbyebye = postcss.plugin('css-byebye', function (options) {
rule.remove()
}
}

css.walkAtRules(filterAtRule)

function filterAtRule (rule) {
var ruleName = '@' + rule.name

if (ruleName.match(regex) !== null) {
rule.remove()
}
}
}
})

Expand Down
11 changes: 11 additions & 0 deletions lib/css-byebye.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,15 @@ describe('cssbyebye', function () {
assert.strictEqual(result.css, expected)
done()
})

it('should remove at-rules', function (done) {
var css = '@charset "UTF-8"; @font-face { font-family: "Font Name" } #id { color: red }'
var rulesToRemove = ['@charset', '@font-face']
var expected = '#id { color: red }'
var options = { rulesToRemove: rulesToRemove, map: false }
var result = postcss(cssbyebye(options)).process(css)

assert.strictEqual(result.css, expected)
done()
})
})

0 comments on commit 0badb2f

Please sign in to comment.