From 1332b88b3e01b623ff81a0216b7dd527f54a7193 Mon Sep 17 00:00:00 2001 From: Saiichi Hashimoto Date: Thu, 5 May 2016 18:16:08 -0700 Subject: [PATCH 1/2] Run postcss plugins before the default --- README.md | 3 ++- index.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c14c61..0212500 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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`. diff --git a/index.js b/index.js index 1fb773c..98da524 100644 --- a/index.js +++ b/index.js @@ -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 = postcssBefore.concat(plugins).concat(postcssAfter); // load plugins by name (if a string is used) plugins = plugins.map(function requirePlugin (name) { From b2d62ecd19efcbff14cfba1792b9ea214f6e40a9 Mon Sep 17 00:00:00 2001 From: Saiichi Hashimoto Date: Thu, 5 May 2016 18:38:21 -0700 Subject: [PATCH 2/2] Account for `before` not being an array sometimes --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 98da524..c36f8fe 100644 --- a/index.js +++ b/index.js @@ -114,7 +114,7 @@ module.exports = function (browserify, options) { var postcssBefore = options.postcssBefore || options.before || []; var postcssAfter = options.postcssAfter || options.after || []; - plugins = postcssBefore.concat(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) {