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 Options" src="http://michael-ciniawsky.github.io/postcss-load-options/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">
14 <img width="100" height="100" title="Load Plugins" src="http://michael-ciniawsky.github.io/postcss-load-plugins/logo.svg">
18 <h2 align="center">Install</h2>
21 npm i -D postcss-load-config
24 <h2 align="center">Usage</h2>
27 npm i -S|-D postcss-plugin
30 Install plugins and save them to your ***package.json*** dependencies/devDependencies.
34 Create **`postcss`** section in your projects **`package.json`**.
49 "from": "/path/to/src.sss",
50 "to": "/path/to/dest.css",
60 Create a **`.postcssrc`** file in JSON or YAML format.
62 It's also allowed to use extensions (**`.postcssrc.json`** or **`.postcssrc.yaml`**). That could help your text editor to properly interpret the file.
69 |- (.postcssrc|.postcssrc.json|.postcssrc.yaml)
78 "from": "/path/to/src.sss",
79 "to": "/path/to/dest.css",
90 from: "/path/to/src.sss"
91 to: "/path/to/dest.css"
96 ### `postcss.config.js` or `.postcssrc.js`
98 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`**.
105 |- (postcss.config.js|.postcssrc.js)
109 You can export the config as an `{Object}`
115 from: '/path/to/src.sss',
116 to: '/path/to/dest.css',
123 Or export a `{Function}` that returns the config (more about the param `ctx` below)
126 module.exports = (ctx) => ({
127 parser: ctx.parser ? 'sugarss' : false,
128 map: ctx.env === 'development' ? ctx.map : false,
132 'postcss-plugin': ctx.plugin
137 Plugins can be loaded in either using an `{Object}` or an `{Array}`.
142 module.exports = (ctx) => ({
145 'postcss-plugin': ctx.plugin
153 module.exports = (ctx) => ({
156 require('postcss-plugin')(ctx.plugin)
160 > :warning: When using an Array, make sure to `require()` them.
162 <h2 align="center">Options</h2>
173 'syntax': 'postcss-scss'
178 'stringifier': 'midas'
181 [**`map`**:](https://github.com/postcss/postcss/blob/master/docs/source-maps.md)
190 from: 'path/to/src.css'
196 to: 'path/to/dest.css'
199 <h2 align="center">Plugins</h2>
203 **`{} || null`**: Plugin loads with defaults.
206 'postcss-plugin': {} || null
208 > :warning: `{}` must be an **empty** object
210 **`[Object]`**: Plugin loads with given options.
213 'postcss-plugin': { option: '', option: '' }
216 **`false`**: Plugin will not be loaded.
219 'postcss-plugin': false
224 Plugin **order** is determined by declaration in the plugins section.
229 'postcss-plugin': {}, // plugins[0]
230 'postcss-plugin': {}, // plugins[1]
231 'postcss-plugin': {} // plugins[2]
236 <h2 align="center">Context</h2>
238 When using a function (`postcss.config.js` or `.postcssrc.js`), it is possible to pass context to `postcss-load-config`, which will be evaluated while loading your config. By default `ctx.env (process.env.NODE_ENV)` and `ctx.cwd (process.cwd())` are available.
240 <h2 align="center">Examples</h2>
242 **postcss.config.js**
245 module.exports = (ctx) => ({
246 parser: ctx.parser ? 'sugarss' : false,
247 map: ctx.env === 'development' ? ctx.map : false,
249 'postcss-import': {},
250 'postcss-nested': {},
251 cssnano: ctx.env === 'production' ? {} : false
256 ### <img width="80" height="80" src="https://worldvectorlogo.com/logos/nodejs-icon.svg">
260 "build": "NODE_ENV=production node postcss",
261 "start": "NODE_ENV=development node postcss"
266 const { readFileSync } = require('fs')
268 const postcss = require('postcss')
269 const postcssrc = require('postcss-load-config')
271 const css = readFileSync('index.sss', 'utf8')
273 const ctx = { parser: true, map: 'inline' }
275 postcssrc(ctx).then(({ plugins, options }) => {
277 .process(css, options)
278 .then((result) => console.log(result.css))
282 ### <img width="80" height="80" src="https://worldvectorlogo.com/logos/gulp.svg">
286 "build": "NODE_ENV=production gulp",
287 "start": "NODE_ENV=development gulp"
292 const { task, src, dest, series, watch } = require('gulp')
294 const postcss = require('gulp-postcssrc')
302 task('watch', () => {
303 watch(['src/*.css', 'postcss.config.js'], css)
306 task('default', series(css, 'watch'))
309 ### <img width="80" height="80" src="https://worldvectorlogo.com/logos/webpack.svg">
313 "build": "NODE_ENV=production webpack",
314 "start": "NODE_ENV=development webpack-dev-server"
319 module.exports = (env) => ({
327 loader: 'css-loader',
328 options: { importLoaders: 1 } }
338 <h2 align="center">Maintainers</h2>
344 <img width="150 height="150"
345 src="https://avatars.githubusercontent.com/u/5419992?v=3&s=150">
347 <a href="https://github.com/michael-ciniawsky">Michael Ciniawsky</a>
350 <img width="150 height="150"
351 src="https://avatars.githubusercontent.com/u/2437969?v=3&s=150">
353 <a href="https://github.com/ertrzyiks">Mateusz Derks</a>
359 <h2 align="center">Contributors</h2>
365 <img width="150" height="150"
366 src="https://avatars.githubusercontent.com/u/1483538?v=3&s=150">
368 <a href="https://github.com/sparty02">Ryan Dunckel</a>
371 <img width="150" height="150"
372 src="https://avatars.githubusercontent.com/u/6249643?v=3&s=150">
374 <a href="https://github.com/pcgilday">Patrick Gilday</a>
377 <img width="150" height="150"
378 src="https://avatars.githubusercontent.com/u/5603632?v=3&s=150">
380 <a href="https://github.com/daltones">Dalton Santos</a>
386 [npm]: https://img.shields.io/npm/v/postcss-load-config.svg
387 [npm-url]: https://npmjs.com/package/postcss-load-config
389 [node]: https://img.shields.io/node/v/postcss-load-plugins.svg
390 [node-url]: https://nodejs.org/
392 [deps]: https://david-dm.org/michael-ciniawsky/postcss-load-config.svg
393 [deps-url]: https://david-dm.org/michael-ciniawsky/postcss-load-config
395 [style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
396 [style-url]: http://standardjs.com/
398 [tests]: http://img.shields.io/travis/michael-ciniawsky/postcss-load-config.svg
399 [tests-url]: https://travis-ci.org/michael-ciniawsky/postcss-load-config
401 [cover]: https://coveralls.io/repos/github/michael-ciniawsky/postcss-load-config/badge.svg
402 [cover-url]: https://coveralls.io/github/michael-ciniawsky/postcss-load-config
404 [chat]: https://img.shields.io/gitter/room/postcss/postcss.svg
405 [chat-url]: https://gitter.im/postcss/postcss