Skip to content
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ The following PostCSS plugins are enabled by default:

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

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

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

An example of this would be:

Expand Down
44 changes: 24 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,36 @@ module.exports = function (browserify, options) {
if (typeof plugins === 'string') {
plugins = [ plugins ];
}
}

plugins = plugins.map(function requirePlugin (name) {
// assume functions are already required plugins
if (typeof name === 'function') {
return name;
}
var postcssAfter = options.postcssAfter || options.after || [];
plugins = plugins.concat(postcssAfter);

var plugin = require(require.resolve(name));
// load plugins by name (if a string is used)
plugins = plugins.map(function requirePlugin (name) {
// assume functions are already required plugins
if (typeof name === 'function') {
return name;
}

// custom scoped name generation
if (name === 'postcss-modules-scope') {
options[name] = options[name] || {};
if (!options[name].generateScopedName) {
options[name].generateScopedName = createScopedNameFunc(plugin);
}
}
var plugin = require(require.resolve(name));

if (name in options) {
plugin = plugin(options[name]);
} else {
plugin = plugin.postcss || plugin();
// custom scoped name generation
if (name === 'postcss-modules-scope') {
options[name] = options[name] || {};
if (!options[name].generateScopedName) {
options[name].generateScopedName = createScopedNameFunc(plugin);
}
}

return plugin;
});
}
if (name in options) {
plugin = plugin(options[name]);
} else {
plugin = plugin.postcss || plugin();
}

return plugin;
});

// keep track of css files visited
var filenames = [];
Expand Down