Skip to content

Commit

Permalink
Set up CSS modules in production
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfranklin committed Jul 18, 2016
1 parent 6d399f6 commit 67a2e39
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -4,8 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "tape -r babel-register -r ./test/setup-jsdom.js test/*-test.js | faucet",
"build-prod": "webpack --config webpack.config.prod.js --progress"
"build-prod": "webpack --config webpack.config.prod.js --progress",
"start": "node dev-server.js"
},
"keywords": [],
"author": "",
Expand All @@ -19,6 +19,7 @@
"css-loader": "0.23.1",
"enzyme": "2.3.0",
"express": "4.13.4",
"extract-text-webpack-plugin": "1.0.1",
"faucet": "0.0.1",
"react-addons-test-utils": "15.1.0",
"react-hot-loader": "1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Expand Up @@ -15,7 +15,7 @@ export default class App extends React.Component {

render() {
return (
<div className={styles.root}>
<div className={styles.app}>
<p>{ this.state.count }</p>
<button onClick={() => this.increment()}>Increment</button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/app.css
@@ -1,3 +1,3 @@
.root p {
color: red;
.app p {
color: green;
}
17 changes: 16 additions & 1 deletion webpack.config.prod.js
@@ -1,5 +1,7 @@
var path = require('path');
var webpack = require('webpack');
var combineLoaders = require('webpack-combine-loaders');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
entry: './src/index.js',
Expand All @@ -8,6 +10,7 @@ module.exports = {
filename: 'bundle.js'
},
plugins: [
new ExtractTextPlugin('styles.css'),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
Expand All @@ -19,13 +22,25 @@ module.exports = {
}
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin()
new webpack.optimize.DedupePlugin(),
],
module: {
loaders: [{
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract(
'style-loader',
combineLoaders([{
loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
}])
)
}]
}
};

0 comments on commit 67a2e39

Please sign in to comment.