Skip to content

Commit 8d52f0d

Browse files
ro-savageTimer
authored andcommitted
Update css modules class naming convention
1 parent 4e9c9da commit 8d52f0d

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

Diff for: packages/react-scripts/config/webpack.config.dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ module.exports = {
252252
options: {
253253
importLoaders: 1,
254254
modules: true,
255-
localIdentName: '[path][name]__[local]',
255+
localIdentName: '[path]__[name]___[local]',
256256
},
257257
},
258258
{

Diff for: packages/react-scripts/config/webpack.config.prod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ module.exports = {
289289
minimize: true,
290290
sourceMap: shouldUseSourceMap,
291291
modules: true,
292-
localIdentName: '[path][name]__[local]',
292+
localIdentName: '[path]__[name]___[local]',
293293
},
294294
},
295295
{

Diff for: packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Integration', () => {
2727
expect(
2828
doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
2929
).to.match(
30-
/.+style-module__cssModulesInclusion+\{background:.+;color:.+}/
30+
/.+__style-module___cssModulesInclusion+\{background:.+;color:.+}/
3131
);
3232
});
3333

Diff for: packages/react-scripts/template/README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ If you are concerned about using Webpack-specific semantics, you can put all you
516516

517517
## Adding a CSS Modules stylesheet
518518

519-
This project supports [CSS Modules](https://github.com/css-modules/css-modules) alongside regular stylesheets using the **[name].module.css** file naming convention. CSS Modules allows the scoping of CSS by automatically prefixing class names with a unique name and hash.
519+
This project supports [CSS Modules](https://github.com/css-modules/css-modules) alongside regular stylesheets using the **[name].module.css** file naming convention. CSS Modules allows the scoping of CSS by automatically creating a unique classname of the format **[dir]\_\_[filename]___[classname]**.
520520

521521
An advantage of this is the ability to repeat the same classname within many CSS files without worrying about a clash.
522522

@@ -540,7 +540,8 @@ An advantage of this is the ability to repeat the same classname within many CSS
540540

541541
```js
542542
import React, { Component } from 'react';
543-
import styles from './Button.module.css'; // Import stylesheet as styles
543+
import './another-stylesheet.css'; // Import regular stylesheet
544+
import styles from './Button.module.css'; // Import css modules stylesheet as styles
544545

545546
class Button extends Component {
546547
render() {
@@ -553,10 +554,10 @@ class Button extends Component {
553554
No clashes from other `.button` classnames
554555

555556
```html
556-
<div class="Button-module__button___1o1Ru"></div>
557+
<div class="src__Button-module___button"></div>
557558
```
558559

559-
**This is an optional feature.** Regular stylesheets and imported stylesheets are fully supported. CSS Modules are only added when explictly named as a css module stylesheet using the extension `.module.css`.
560+
**This is an optional feature.** Regular html stylesheets and js imported stylesheets are fully supported. CSS Modules are only added when explictly named as a css module stylesheet using the extension `.module.css`.
560561

561562
## Post-Processing CSS
562563

0 commit comments

Comments
 (0)