Skip to content

Commit e653f4b

Browse files
author
Jeff Escalante
committed
Merge pull request #46 from carrot/postcss-opts
Allow postcss options to be passed through
2 parents 5f2ff6d + fcc6ae1 commit e653f4b

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lib/config.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export default class Config {
3030
css: Joi.string().default('**/*.css'),
3131
js: Joi.string().default('**/*.js')
3232
}),
33-
postCssPlugins: Joi.array().default([]),
33+
postcss: Joi.object().default().keys({
34+
plugins: Joi.array().default([]),
35+
options: Joi.object().default({})
36+
}),
3437
babelConfig: Joi.object().default({}),
3538
dumpDirs: Joi.array().default(['views', 'assets']),
3639
locals: Joi.object().default({}),
@@ -117,16 +120,16 @@ export default class Config {
117120

118121
this.module = {
119122
loaders: [
120-
{ test: mmToRe(opts.matchers.css), exclude: opts.ignore.map(mmToRe), loader: 'css!postcss' },
123+
{ test: mmToRe(opts.matchers.css), exclude: opts.ignore.map(mmToRe), loader: `css!postcss?${JSON.stringify(opts.postcss.options)}` },
121124
{ test: mmToRe(opts.matchers.js), exclude: opts.ignore.map(mmToRe), loader: 'babel' },
122-
{ test: mmToRe(opts.matchers.jade), exclude: opts.ignore.map(mmToRe), loader: 'jade?pretty=true' }
125+
{ test: mmToRe(opts.matchers.jade), exclude: opts.ignore.map(mmToRe), loader: 'jade', query: { pretty: true } }
123126
]
124127
}
125128

126129
this.postcss = function (wp) {
127130
let res = [postcssImport({ addDependencyTo: wp })]
128-
res.push(...opts.postCssPlugins)
129-
return opts.postCssPlugins
131+
res.push(...opts.postcss.plugins)
132+
return opts.postcss.plugins
130133
}
131134

132135
this.modulesDirectories = opts.modulesDirectories

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The above shows a minimal instantiation, but the constructor accepts a wide vari
4040

4141
- **root**: An absolute path to the root of your project.
4242
- **matchers**: An object with `jade`, `css`, and `js` keys. Each key is a [micromatch](https://github.com/jonschlinkert/micromatch) string, and represents which files should be pulled into the pipeline to be processed. Defaults are `**/*.jade`, `**/*.css`, and `**/*.js`. Be very careful if you are trying to change this.
43-
- **postCssPlugins**: An array of [plugins to be passed to PostCSS](http://postcss.parts/) for CSS processing.
43+
- **postcss**: An object that can contain a `plugins` key, which is an array of [plugins to be passed to PostCSS](http://postcss.parts/) for CSS processing, and/or a `options` key, which takes [any of the postcss-loader options](https://github.com/postcss/postcss-loader#custom-syntaxes).
4444
- **babelConfig**: A [configuration object for Babel](http://babeljs.io/docs/usage/options/) for JS processing.
4545
- **dumpDirs**: An array of directories which, if direct children of the project root, will dump their contents to the root on compile. Defaults to `['views', 'assets']`.
4646
- **locals**: An object containing locals to be passed to jade views. This can be used for values, functions, any sort of view helper you need.

test/config_errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ test('config errors', (t) => {
88
'ValidationError: child "matchers" fails because ["matchers" must be an object]')
99
t.throws(() => { new Roots({ root: 'foo', matchers: { css: [1] } }) }, // eslint-disable-line
1010
'ValidationError: child "matchers" fails because [child "css" fails because ["css" must be a string]]')
11-
t.throws(() => { new Roots({ root: 'foo', postCssPlugins: function () {} }) }, // eslint-disable-line
12-
'ValidationError: child "postCssPlugins" fails because ["postCssPlugins" must be an array]')
11+
t.throws(() => { new Roots({ root: 'foo', postcss: function () {} }) }, // eslint-disable-line
12+
'ValidationError: child "postcss" fails because ["postcss" must be an object]')
1313
t.throws(() => { new Roots({ root: 'foo', babelConfig: 'wow' }) }, // eslint-disable-line
1414
'ValidationError: child "babelConfig" fails because ["babelConfig" must be an object]')
1515
t.throws(() => { new Roots({ root: 'foo', entry: ['foo', 'bar'] }) }, // eslint-disable-line

0 commit comments

Comments
 (0)