Skip to content

Commit ded3433

Browse files
committed
Merge pull request #27 from css-modules/postcss-after
new option `--after` and updated readme
2 parents aeea32e + 3cc6dc6 commit ded3433

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ The following PostCSS plugins are enabled by default:
6161

6262
(i.e. the [CSS Modules] specification).
6363

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

66-
In addion you may also wish to configure defined PostCSS plugins by passing `--plugin.option true`.
66+
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).
67+
68+
In addition you may also wish to configure defined PostCSS plugins by passing `--plugin.option true`.
6769

6870
An example of this would be:
6971

index.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,36 @@ module.exports = function (browserify, options) {
3737
if (typeof plugins === 'string') {
3838
plugins = [ plugins ];
3939
}
40+
}
4041

41-
plugins = plugins.map(function requirePlugin (name) {
42-
// assume functions are already required plugins
43-
if (typeof name === 'function') {
44-
return name;
45-
}
42+
var postcssAfter = options.postcssAfter || options.after || [];
43+
plugins = plugins.concat(postcssAfter);
4644

47-
var plugin = require(require.resolve(name));
45+
// load plugins by name (if a string is used)
46+
plugins = plugins.map(function requirePlugin (name) {
47+
// assume functions are already required plugins
48+
if (typeof name === 'function') {
49+
return name;
50+
}
4851

49-
// custom scoped name generation
50-
if (name === 'postcss-modules-scope') {
51-
options[name] = options[name] || {};
52-
if (!options[name].generateScopedName) {
53-
options[name].generateScopedName = createScopedNameFunc(plugin);
54-
}
55-
}
52+
var plugin = require(require.resolve(name));
5653

57-
if (name in options) {
58-
plugin = plugin(options[name]);
59-
} else {
60-
plugin = plugin.postcss || plugin();
54+
// custom scoped name generation
55+
if (name === 'postcss-modules-scope') {
56+
options[name] = options[name] || {};
57+
if (!options[name].generateScopedName) {
58+
options[name].generateScopedName = createScopedNameFunc(plugin);
6159
}
60+
}
6261

63-
return plugin;
64-
});
65-
}
62+
if (name in options) {
63+
plugin = plugin(options[name]);
64+
} else {
65+
plugin = plugin.postcss || plugin();
66+
}
67+
68+
return plugin;
69+
});
6670

6771
// keep track of css files visited
6872
var filenames = [];

0 commit comments

Comments
 (0)