Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
Pass options from config to postcss-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Aug 18, 2016
1 parent bc60ffe commit 3f8aad0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ module.exports = {
};
```

You can also pass options directly to
[postcss-modules](https://github.com/css-modules/postcss-modules):

```javascript
module.exports = {
// ...
plugins: {
css: {
modules: {
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
}
};
```

Then, author your styles like you normally would:

```css
Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
const postcss = require('postcss');
const postcssModules = require('postcss-modules');

const cssModulify = (path, data, map) => {
const cssModulify = (path, data, map, options) => {
let json = {};
const getJSON = (_, _json) => json = _json;

return postcss([postcssModules({getJSON})]).process(data, {from: path, map}).then(x => {
const exports = 'module.exports = ' + JSON.stringify(json) + ';';
return { data: x.css, map: x.map, exports };
});
return postcss([postcssModules(Object.assign({}, {getJSON}, options))])
.process(data, {from: path, map}).then(x => {
const exports = 'module.exports = ' + JSON.stringify(json) + ';';
return { data: x.css, map: x.map, exports };
});
};

class CSSCompiler {
Expand All @@ -21,7 +22,8 @@ class CSSCompiler {
}
compile(params) {
if (this.modules) {
return cssModulify(params.path, params.data, params.map);
const moduleOptions = this.modules === true ? {} : this.modules;
return cssModulify(params.path, params.data, params.map, moduleOptions);
} else {
return Promise.resolve(params);
}
Expand Down

0 comments on commit 3f8aad0

Please sign in to comment.