2 [![node][node]][node-url]
3 [![deps][deps]][deps-url]
4 [![tests][tests]][tests-url]
5 [![coverage][cover]][cover-url]
6 [![code style][style]][style-url]
7 [![chat][chat]][chat-url]
10 <img width="100" height="100" title="Load Plugins" src="http://michael-ciniawsky.github.io/postcss-load-plugins/logo.svg">
11 <a href="https://github.com/postcss/postcss">
12 <img width="110" height="110" title="PostCSS" src="http://postcss.github.io/postcss/logo.svg" hspace="10">
17 <h2 align="center">Install</h2>
20 npm i -D postcss-load-plugins
23 <h2 align="center">Usage</h2>
26 npm i -S|-D postcss-plugin
29 Install plugins and save them to your ***package.json*** dependencies/devDependencies.
33 Create **`postcss`** section in your projects **`package.json`**.
55 Create a **`.postcssrc`** file.
62 |- (.postcssrc|.postcssrc.json|.postcssrc.yaml)
81 ### `postcss.config.js` or `.postcssrc.js`
83 You may need some JavaScript logic to generate your config. For this case you can use a file named **`postcss.config.js`** or **`.postcssrc.js`**.
90 |- (postcss.config.js|.postcssrc.js)
94 Plugins can be loaded in either using an `{Object}` or an `{Array}`.
99 module.exports = (ctx) => ({
101 'postcss-plugin': ctx.plugin
109 module.exports = (ctx) => ({
111 require('postcss-plugin')(ctx.plugin)
116 <h2 align="center">Options</h2>
118 Plugin **options** can take the following values.
120 **`{}`: Plugin loads with defaults**
123 'postcss-plugin': {} || null
126 > :warning: `{}` must be an **empty** object
128 **`{Object}`: Plugin loads with options**
131 'postcss-plugin': { option: '', option: '' }
134 **`false`: Plugin will not be loaded**
137 'postcss-plugin': false
142 Plugin **order** is determined by declaration in the plugins section.
147 'postcss-plugin': {}, // plugins[0]
148 'postcss-plugin': {}, // plugins[1]
149 'postcss-plugin': {} // plugins[2]
156 When using a function `(postcss.config.js)`, it is possible to pass context to `postcss-load-plugins`, which will be evaluated before loading your plugins. By default `ctx.env (process.env.NODE_ENV)` and `ctx.cwd (process.cwd())` are available.
158 <h2 align="center">Examples</h2>
160 **`postcss.config.js`**
163 module.exports = (ctx) => ({
166 postcss-modules: ctx.modules ? {} : false,
167 cssnano: ctx.env === 'production' ? {} : false
172 ### <img width="80" height="80" src="https://worldvectorlogo.com/logos/nodejs-icon.svg">
175 const { readFileSync } = require('fs')
177 const postcss = require('postcss')
178 const pluginsrc = require('postcss-load-plugins')
180 const css = readFileSync('index.css', 'utf8')
182 const ctx = { modules: true }
184 pluginsrc(ctx).then((plugins) => {
187 .then((result) => console.log(result.css))
191 <h2 align="center">Maintainers</h2>
197 <img width="150" height="150"
198 src="https://github.com/michael-ciniawsky.png?v=3&s=150">
200 <a href="https://github.com/michael-ciniawsky">Michael Ciniawsky</a>
203 <img width="150" height="150"
204 src="https://github.com/ertrzyiks.png?v=3&s=150">
206 <a href="https://github.com/ertrzyiks">Mateusz Derks</a>
212 <h2 align="center">Contributors</h2>
218 <img width="150" height="150"
219 src="https://github.com/Kovensky.png?v=3&s=150">
221 <a href="https://github.com/Kovensky">Diogo Franco</a>
228 [npm]: https://img.shields.io/npm/v/postcss-load-plugins.svg
229 [npm-url]: https://npmjs.com/package/postcss-load-plugins
231 [node]: https://img.shields.io/node/v/postcss-load-plugins.svg
232 [node-url]: https://nodejs.org/
234 [deps]: https://david-dm.org/michael-ciniawsky/postcss-load-plugins.svg
235 [deps-url]: https://david-dm.org/michael-ciniawsky/postcss-load-plugins
237 [tests]: http://img.shields.io/travis/michael-ciniawsky/postcss-load-plugins.svg
238 [tests-url]: https://travis-ci.org/michael-ciniawsky/postcss-load-plugins
240 [cover]: https://coveralls.io/repos/github/michael-ciniawsky/postcss-load-plugins/badge.svg
241 [cover-url]: https://coveralls.io/github/michael-ciniawsky/postcss-load-plugins
243 [style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
244 [style-url]: http://standardjs.com/
246 [chat]: https://img.shields.io/gitter/room/postcss/postcss.svg
247 [chat-url]: https://gitter.im/postcss/postcss