Skip to content

Run postcss plugins before the default #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ b.on('css stream', function (css) {
- `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.
- `jsonOutput`: optional path to write a json manifest of classnames.
- `use`: optional array of postcss plugins (by default we use the css-modules core plugins). NOTE: it's safer to use `after`
- `before`: optional array of postcss plugins to run before the required css-modules core plugins are run.
- `after`: optional array of postcss plugins to run after the required css-modules core plugins are run.
- `generateScopedName`: (API only) a function to override the default behaviour of creating locally scoped classnames.
- `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).
Expand Down Expand Up @@ -96,7 +97,7 @@ The following PostCSS plugins are enabled by default:

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

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).
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.

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

Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ module.exports = function (browserify, options) {
}
}

var postcssBefore = options.postcssBefore || options.before || [];
var postcssAfter = options.postcssAfter || options.after || [];
plugins = plugins.concat(postcssAfter);
plugins = (Array.isArray(postcssBefore) ? postcssBefore : [postcssBefore]).concat(plugins).concat(postcssAfter);

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