Skip to content

Commit 7fd7d90

Browse files
committed
add ability to pass options to postcss plugins
1 parent e5b2d95 commit 7fd7d90

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Missing a configuration? [Raise an issue](https://github.com/gajus/babel-plugin-
208208
```js
209209
type FiletypeOptionsType = {|
210210
+syntax: string,
211-
+plugins?: $ReadOnlyArray<string>
211+
+plugins?: $ReadOnlyArray<string | $ReadOnlyArray<[string, mixed]>>
212212
|};
213213

214214
type FiletypesConfigurationType = {
@@ -251,7 +251,12 @@ To add support for different CSS syntaxes (e.g. SCSS), perform the following two
251251
"filetypes": {
252252
".scss": {
253253
"syntax": "postcss-scss",
254-
"plugins": ["postcss-nested"]
254+
"plugins": [
255+
["postcss-import-sync2", {
256+
"path": ["src/styles", "shared/styles"]
257+
}],
258+
"postcss-nested"
259+
]
255260
}
256261
}
257262
```

src/requireCssModule.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121

2222
type FiletypeOptionsType = {|
2323
+syntax: string,
24-
+plugins?: $ReadOnlyArray<string>
24+
+plugins?: $ReadOnlyArray<string | $ReadOnlyArray<[string, mixed]>>
2525
|};
2626

2727
type FiletypesConfigurationType = {
@@ -52,6 +52,13 @@ const getExtraPlugins = (filetypeOptions: ?FiletypeOptionsType): $ReadOnlyArray<
5252
}
5353

5454
return filetypeOptions.plugins.map((plugin) => {
55+
if (Array.isArray(plugin)) {
56+
const [pluginName, pluginOptions] = plugin;
57+
58+
// eslint-disable-next-line import/no-dynamic-require, global-require
59+
return require(pluginName)(pluginOptions);
60+
}
61+
5562
// eslint-disable-next-line import/no-dynamic-require, global-require
5663
return require(plugin);
5764
});

src/schemas/optionsSchema.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
"properties": {
1616
"plugins": {
1717
"items": {
18-
"type": "string"
18+
"oneOf": [
19+
{
20+
"type": "string"
21+
},
22+
{
23+
"type": "array"
24+
}
25+
]
1926
},
2027
"type": "array"
2128
},

0 commit comments

Comments
 (0)