Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit e7eedde

Browse files
committed
Add plugins option
Close #118
1 parent 91177c8 commit e7eedde

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
- Added: `plugins` option that allows you to pipe your own transformation ([#118](https://github.com/cssnext/cssnext/issues/118))
3+
14
# 1.6.0 - 2015-06-02
25

36
- Added: prevent mutability issues with frozen options objects ([#147](https://github.com/cssnext/cssnext/pull/147))

docs/content/usage.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ By default, `url()` are rebased according to `from` (and `to`) option(s). This i
9696

9797
_Note: you can pass [postcss-url options](https://github.com/postcss/postcss-url#options) directly in order to inline or have more control over urls._
9898

99+
## `plugins`
100+
101+
(default: undefined)
102+
103+
Allows you to pass your own array of transformations. You can just pass your own
104+
[PostCSS](https://github.com/postcss/postcss) plugins.
105+
106+
```js
107+
{
108+
plugins: [
109+
require("postcss-sass-stuff"),
110+
require("postcss-more-crazy-stuff"),
111+
// custom transformation code
112+
function(styles) {
113+
114+
},
115+
],
116+
}
117+
```
118+
99119
## `compress`
100120

101121
(default: `false`)

src/__tests__/option.plugins.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import test from "tape"
2+
3+
import cssnext from ".."
4+
5+
test("cssnext option: plugins", (t) => {
6+
7+
t.equal(
8+
cssnext(
9+
":root{} @notOk",
10+
{
11+
plugins: [
12+
styles => {
13+
styles.eachAtRule(atRule => {
14+
atRule.name = "ok"
15+
})
16+
},
17+
],
18+
}
19+
),
20+
"@ok",
21+
"should allow to add custom plugins"
22+
)
23+
24+
t.end()
25+
})

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ function cssnext(string, options) {
198198
}
199199
})
200200

201+
if (options.plugins) {
202+
if (!Array.isArray(options.plugins)) {
203+
throw new Error(
204+
"cssnext 'plugins' option expect an array of PostCSS plugins. " +
205+
"You provided " + (typeof options.plugins)
206+
)
207+
}
208+
209+
options.plugins.forEach(plugin => postcssInstance.use(plugin))
210+
}
211+
201212
// minification
202213
if (options.compress) {
203214
var nano = require("cssnano")

0 commit comments

Comments
 (0)