Package Exports
- postcss-load-plugins
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (postcss-load-plugins) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
postcss-load-plugins
Loads in any postcss plugins and attaches them to the global scope, or an object of your choice.
Install
npm i postcss-load-plugins
Usage
Given a package.json
file that has some dependencies within:
{
"dependencies": {
"postcss-nested": "*",
"postcss-mixin": "*",
"autoprefixer-core": "*"
}
}
var plugins = require('postcss-load-plugins')();
Will result in the following happening (roughly, plugins are lazy loaded but in practice you won't notice any difference):
plugins.nested = require('postcss-nested');
plugins.mixin = require('postcss-mixin');
plugins.autoprefixer = require('autoprefixer-core');
You can then use the plugins just like you would if you'd manually required them, but referring to them as plugins.name()
, rather than just name()
.
This frees you up from having to manually require each postcss plugin.
Options
You can pass in an object of options that are shown below: (the values for the keys are the defaults):
require('postcss-load-plugins')({
pattern: [], // the glob(s) to search for. registry.json contains common modules
config: 'package.json', // where to find the plugins, by default searched up from process.cwd()
scope: ['dependencies', 'devDependencies', 'peerDependencies'], // which keys in the config to look within
replaceString: /^postcss-/, // what to remove from the name of the module when adding it to the context
camelize: true, // if true, transforms hyphenated plugins names to camel case
rename: {}, // a mapping of plugins to rename
});
Renaming
You can pass in an object of mappings for renaming plugins. For example, imagine you want to load the css-mqpacker
plugin, but want to refer to it as just mqpacker
:
require('postcss-load-plugins')({
rename: {
'css-mqpacker': 'mqpacker'
}
});
Default renames
{
"autoprefixer-core": "autoprefixer",
"css-mqpacker": "mqpacker",
"css-byebye": "byebye"
}
License
Copyright © 2015 Sindre Sorhus, Jack Franklin, Bogdan Chadkin