Skip to content

Commit 1e760a5

Browse files
committed
Add example in the readme how to pass CSS modules as object
1 parent 8d1ad3c commit 1e760a5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,29 @@ posthtml([require('posthtml-css-modules')('./cssModules/')])
7575
// <div class="baseWrapper _profile_user_f93j">John</div>
7676
// <h2 class="_article__tile _heading"></h2>
7777
```
78+
79+
80+
### Object
81+
You can also pass CSS modules as an object to the plugin:
82+
```
83+
var posthtml = require('posthtml'),
84+
cssModules = {
85+
title: "_title_116zl_1 _heading_9dkf",
86+
profile: {
87+
user: "_profile_user_f93j"
88+
}
89+
};
90+
91+
posthtml([require('posthtml-css-modules')(cssModules)])
92+
.process(
93+
'<h1 css-module="title">My profile</h1>' +
94+
// You can also use nested modules
95+
'<div css-module="profile.user">John</div>'
96+
)
97+
.then(function (result) {
98+
console.log(result.html);
99+
});
100+
101+
// <h1 class="_title_116zl_1 _heading_9dkf">My profile</h1>
102+
// <div class="_profile_user_f93j">John</div>
103+
```

0 commit comments

Comments
 (0)