Skip to content

Commit 97403f2

Browse files
committed
Merge pull request #97 from saiichihashimoto/master
Run postcss plugins before the default
2 parents a0b2f24 + b2d62ec commit 97403f2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ b.on('css stream', function (css) {
6767
- `output`: path to write the generated css. If not provided, you'll need to listen to the `'css stream'` event on the bundle to get the output.
6868
- `jsonOutput`: optional path to write a json manifest of classnames.
6969
- `use`: optional array of postcss plugins (by default we use the css-modules core plugins). NOTE: it's safer to use `after`
70+
- `before`: optional array of postcss plugins to run before the required css-modules core plugins are run.
7071
- `after`: optional array of postcss plugins to run after the required css-modules core plugins are run.
7172
- `generateScopedName`: (API only) a function to override the default behaviour of creating locally scoped classnames.
7273
- `global`: optional boolean. Set to `true` if you want `css-modulesify` to apply to `node_modules` as well as local files. You can read more about it in the [browserify docs](https://github.com/substack/node-browserify/#btransformtr-opts).
@@ -96,7 +97,7 @@ The following PostCSS plugins are enabled by default:
9697

9798
You can override the default PostCSS Plugins (and add your own) by passing `--use|-u` to `css-modulesify`.
9899

99-
Or if you just want to add some extra plugins to run after the default, add them to the `postcssAfter` array option (API only at this time).
100+
Or if you just want to add some extra plugins to run after the default, add them to the `postcssAfter` array option (API only at this time). In the same way, add extra plugins to `postcssBefore` to run the before the defaults.
100101

101102
In addition you may also wish to configure defined PostCSS plugins by passing `--plugin.option true`.
102103

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ module.exports = function (browserify, options) {
112112
}
113113
}
114114

115+
var postcssBefore = options.postcssBefore || options.before || [];
115116
var postcssAfter = options.postcssAfter || options.after || [];
116-
plugins = plugins.concat(postcssAfter);
117+
plugins = (Array.isArray(postcssBefore) ? postcssBefore : [postcssBefore]).concat(plugins).concat(postcssAfter);
117118

118119
// load plugins by name (if a string is used)
119120
plugins = plugins.map(function requirePlugin (name) {

0 commit comments

Comments
 (0)