Skip to content

Commit 77609c3

Browse files
committed
patterns
1 parent 67007d1 commit 77609c3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

demo/readme.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ Open <a href="http://localhost:3000/" target="_blank">http://localhost:3000/</a>
1919

2020
## Detailed description
2121

22-
In short [CSS Modules](https://github.com/css-modules/css-modules) provide modularity with generated class names. Therefore, generated names should be present in CSS styles and in templates which form resulting html. Since, we talk about server rendering in the current example I'll show you how to set require hook to generate the same names in runtime as the CSS styles.
22+
In short [CSS&nbsp;Modules](https://github.com/css-modules/css-modules) provide modularity with generated class names. Therefore, generated names should be present in CSS styles and in templates which form resulting html. Since, we talk about server rendering in the current example I'll show you how to set require hook to generate the same names in runtime as the CSS styles.
2323

2424

2525
### Frontend
2626

2727
The modern frontend is so tough that you have to use particular bundler systems in order to generate a simple CSS file. My favourite one is [webpack](https://webpack.github.io/), so I'll show you how to set it with the require hook.
2828

29-
To understand [webpack](https://webpack.github.io/) configs you should be familiar with [loaders](https://webpack.github.io/docs/using-loaders.html). In order to use [CSS Modules](https://github.com/css-modules/css-modules) with [webpack](https://webpack.github.io/) you should set [css-loader](https://github.com/webpack/css-loader#css-modules). Also [extract-text-webpack-plugin](https://github.com/webpack/extract-text-webpack-plugin) provides you possibility to create pure CSS file. So eventually, your configuration should look similar to this:
29+
To understand [webpack](https://webpack.github.io/) configs you should be familiar with [loaders](https://webpack.github.io/docs/using-loaders.html). In order to use [CSS&nbsp;Modules](https://github.com/css-modules/css-modules) with [webpack](https://webpack.github.io/) you should set [css-loader](https://github.com/webpack/css-loader#css-modules). Also [extract-text-webpack-plugin](https://github.com/webpack/extract-text-webpack-plugin) provides you possibility to create pure CSS file. So eventually, your configuration should look similar to this:
3030

3131
```javascript
3232
module: {
@@ -80,3 +80,22 @@ Describes the simple [template engine](http://expressjs.com/en/advanced/developi
8080
// uses external config cmrh.conf.js
8181
require('css-modules-require-hook/preset');
8282
```
83+
84+
**Note** that to generate the same names in runtime as the CSS styles you should provide the same pattern to [webpack](https://webpack.github.io/) and to the require hook.
85+
86+
Use `localIdentName` for [webpack](https://webpack.github.io/):
87+
88+
```javascript
89+
loader: ExtractTextPlugin.extract('style',
90+
'css?modules&localIdentName=[name]_[local]__[hash:base64:5]'),
91+
```
92+
93+
and `generateScopedName` for the require hook. For example, if you use presets then you can put it to the `cmrh.conf.js` file:
94+
95+
```javascript
96+
module.exports = {
97+
// the custom template for the generic classes
98+
generateScopedName: '[name]_[local]__[hash:base64:5]',
99+
};
100+
101+
```

0 commit comments

Comments
 (0)