Skip to content

Commit 0cc0a65

Browse files
committed
Add documentation about CSS Modules.
1 parent 2794dd8 commit 0cc0a65

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Below is a step-by-step guide that takes you straight from downloading this boil
1616
- [Installation](#installation)
1717
- [Development Workflow](#development-workflow)
1818
- [Structure](#structure)
19+
- [CSS Modules](#css-modules)
1920
- [Handling URLS](#handling-urls)
2021

2122

@@ -91,6 +92,36 @@ class Link extends Component {
9192
```
9293

9394

95+
---
96+
97+
98+
## CSS Modules
99+
100+
This project is set up to support [CSS Modules](https://github.com/css-modules/css-modules). By default, styles in `src/style` are **global** (not using CSS Modules) to make global declarations, imports and helpers easy to declare. Styles in `src/components` are loaded as CSS Modules via [Webpack's css-loader](https://github.com/webpack/css-loader#css-modules). Modular CSS namespaces class names, and when imported into JavaScript returns a mapping of canonical (unmodified) CSS classes to their local (namespaced/suffixed) counterparts.
101+
102+
When imported, this LESS/CSS:
103+
104+
```css
105+
.redText { color:red; }
106+
.blueText { color:blue; }
107+
```
108+
109+
... returns the following map:
110+
111+
```js
112+
import styles from './style.css';
113+
console.log(styles);
114+
// {
115+
// redText: 'redText_local_9gt72',
116+
// blueText: 'blueText_local_9gt72'
117+
// }
118+
```
119+
120+
Note that the suffix for local classNames is generated based on an md5 hash of the file. Changing the file changes the hash.
121+
122+
123+
---
124+
94125

95126
## Handling URLS
96127

0 commit comments

Comments
 (0)