Skip to content

Commit eafafb5

Browse files
committed
Feat: Added support for css modules via react-css-modules
1 parent f9c5383 commit eafafb5

File tree

9 files changed

+126
-13
lines changed

9 files changed

+126
-13
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"es2015-native-modules",
44
"react",
55
"airbnb"
6+
],
7+
"plugins": [
8+
"transform-decorators-legacy"
69
]
710
}

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"parser": "babel-eslint",
23
"env": {
34
"browser": true,
45
"node": true,

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ You may use this template either directly (by cloning this git repository) or by
1010
The following features are currently included out of the box:
1111

1212
- [x] Webpack 2 setup to get you started (including basic support for LESS/SASS/SCSS/Stylus and PostCSS)
13-
- [ ] CSS Modules support
13+
- [x] CSS Modules support via https://github.com/gajus/react-css-modules
1414
- [x] Babel 6 to transpile ES2015 and JSX
1515
- [x] Latest stable React Version (v15.0)
16-
- [x] Karma, Mocha, Chai and Enzyme for easier unit testing
17-
- [x] Isparta to collect coverage information
16+
- [x] [Karma](http://karma-runner.github.io), [Mocha](https://mochajs.org), [Chai](http://chaijs.com) and [Enzyme](http://airbnb.io/projects/enzyme/) for easier unit testing
17+
- [x] Istanbul with Isparta to collect coverage information
1818
- [x] Preconfigured .editorconfig file
1919
- [x] Preconfigured eslint configuration, based on airbnb
2020

conf/webpack/Base.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,42 @@ class WebpackBaseConfig {
8484
loaders: [
8585
{
8686
test: /\.css$/,
87-
loaders: ['style', 'css']
87+
loaders: [
88+
'style',
89+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]'
90+
]
8891
},
8992
{
9093
test: /\.sass$/,
91-
loaders: ['style', 'css', 'sass']
94+
loaders: [
95+
'style',
96+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
97+
'sass'
98+
]
9299
},
93100
{
94101
test: /\.scss$/,
95-
loaders: ['style', 'css', 'sass']
102+
loaders: [
103+
'style',
104+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
105+
'sass'
106+
]
96107
},
97108
{
98109
test: /\.less$/,
99-
loaders: ['style', 'css', 'less']
110+
loaders: [
111+
'style',
112+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
113+
'less'
114+
]
100115
},
101116
{
102117
test: /\.styl$/,
103-
loaders: ['style', 'css', 'stylus']
118+
loaders: [
119+
'style',
120+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
121+
'stylus'
122+
]
104123
},
105124
{
106125
test: /\.(png|jpg|gif|mp4|ogg|svg|woff|woff2)$/,

conf/webpack/Dist.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class WebpackDistConfig extends WebpackBaseConfig {
1212
constructor() {
1313
super();
1414
this.config = {
15+
cache: false,
1516
devtool: 'source-map',
1617
plugins: [
1718
new webpack.DefinePlugin({

conf/webpack/Test.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,46 @@ class WebpackTestConfig extends WebpackBaseConfig {
2929
],
3030
loaders: [
3131
{
32-
test: /\.(png|jpg|gif|woff|woff2|css|sass|scss|less|styl|mp4|ogg|svg)$/,
32+
test: /\.css$/,
33+
loaders: [
34+
'style',
35+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]'
36+
]
37+
},
38+
{
39+
test: /\.sass$/,
40+
loaders: [
41+
'style',
42+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
43+
'sass'
44+
]
45+
},
46+
{
47+
test: /\.scss$/,
48+
loaders: [
49+
'style',
50+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
51+
'sass'
52+
]
53+
},
54+
{
55+
test: /\.less$/,
56+
loaders: [
57+
'style',
58+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
59+
'less'
60+
]
61+
},
62+
{
63+
test: /\.styl$/,
64+
loaders: [
65+
'style',
66+
'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
67+
'stylus'
68+
]
69+
},
70+
{
71+
test: /\.(png|jpg|gif|mp4|ogg|svg|woff|woff2)$/,
3372
loader: 'null-loader'
3473
},
3574
{

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"posttest": "npm run lint",
1010
"test:watch": "karma start --autoWatch=true --singleRun=false --reporters=mocha,coverage",
1111
"serve:dev": "webpack-dev-server --open --env dev",
12-
"serve:dist": "webpack-dev-server --open --env dist",
13-
"dist": "npm run clean && webpack --progress --bail --env dist -p",
12+
"serve:dist": "webpack-dev-server --hot --inline --open --progress --env dist -p",
13+
"dist": "npm run clean && npm run copy && webpack --progress --bail --env dist -p",
1414
"lint": "eslint ./src",
1515
"clean": "rimraf dist/*",
16+
"copy": "copyfiles -f ./src/index.html ./src/favicon.ico ./dist",
1617
"release:major": "npm version major && git push --follow-tags",
1718
"release:minor": "npm version minor && git push --follow-tags",
1819
"release:patch": "npm version patch && git push --follow-tags"
@@ -38,12 +39,15 @@
3839
"homepage": "https://github.com/weblogixx/react-webpack-template#readme",
3940
"devDependencies": {
4041
"babel-core": "^6.7.6",
42+
"babel-eslint": "^6.0.4",
4143
"babel-loader": "^6.2.4",
44+
"babel-plugin-transform-decorators-legacy": "^1.3.4",
4245
"babel-polyfill": "^6.9.0",
4346
"babel-preset-airbnb": "^2.0.0",
4447
"babel-preset-es2015-native-modules": "^6.6.0",
4548
"babel-preset-react": "^6.5.0",
4649
"chai": "^3.5.0",
50+
"copyfiles": "^0.2.1",
4751
"css-loader": "^0.23.1",
4852
"enzyme": "^2.2.0",
4953
"eslint": "^2.8.0",
@@ -68,6 +72,7 @@
6872
"null-loader": "^0.1.1",
6973
"phantomjs-prebuilt": "^2.1.7",
7074
"react-addons-test-utils": "^15.0.1",
75+
"react-css-modules": "^3.7.6",
7176
"react-hot-loader": "^1.3.0",
7277
"rimraf": "^2.5.2",
7378
"sinon": "^1.17.3",

src/components/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React from 'react';
2+
import cssmodules from 'react-css-modules';
3+
import styles from './app.css';
24

35
const yeomanImage = require('../images/yeoman.png');
46

7+
@cssmodules(styles)
58
class AppComponent extends React.Component {
69

710
handleClick() {
@@ -10,10 +13,10 @@ class AppComponent extends React.Component {
1013

1114
render() {
1215
return (
13-
<div className="index" onClick={this.handleClick.bind(this)}>
16+
<div className="index" styleName="index" onClick={this.handleClick.bind(this)}>
1417
<img src={yeomanImage} alt="Yeoman Generator" />
1518
<div className="notice">
16-
Please edit <code>src/components/Main.js</code> to get started!
19+
Please edit <code>src/components/App.js</code> to get started!
1720
</div>
1821
</div>
1922
);

src/components/app.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
:global body {
2+
margin: 0;
3+
padding: 0;
4+
font-family: Arial, Helvetica, sans-serif;
5+
font-size: 14px;
6+
color: #fff;
7+
background: #222;
8+
}
9+
10+
.index {
11+
width: 40%;
12+
margin: 50px auto;
13+
padding: 10px;
14+
background: #333;
15+
border: 1px solid #000;
16+
border-radius: 2px;
17+
text-align: center;
18+
box-sizing: border-box;
19+
}
20+
21+
.index code {
22+
padding: 3px 6px;
23+
color: #000;
24+
background: #fff;
25+
font-size: 14px;
26+
}
27+
28+
.index img {
29+
margin: 40px auto;
30+
border-radius: 4px;
31+
background: #fff;
32+
display: block;
33+
}
34+
35+
.notice {
36+
margin: 20px auto;
37+
padding: 15px 0;
38+
text-align: center;
39+
border: 1px solid #000;
40+
border-width: 1px 0;
41+
background: #666;
42+
}

0 commit comments

Comments
 (0)