Nick Nick - 4 months ago 10
Node.js Question

Webpack compiling CSS into strange classnames

I am currently using

webpack
while developing React app with a NodeJS backend.

I am having trouble with styling the app because it seems webpack trying to do something with my css where it ends up changing the classnames.

For instance in my
base.css
file I have this:

body {
background: #ECEFF1;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 15px;
line-height: 1.7;
margin: 0 auto;
padding: 30px;
max-width: 980px;
}

.progress {
background-color: #FFECB3;
}
.progress .indeterminate {
background-color: #FFC107;
}


Which when I load the page and look in the head is converted to a
<style>
div with these classnames:

<style type="text/css">
body {
background: #ECEFF1;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 15px;
line-height: 1.7;
margin: 0 auto;
padding: 30px;
max-width: 980px;
}

.base---progress---1RR8Z {
background-color: #FFECB3;
}
.base---progress---1RR8Z .base---indeterminate---23sZH {
background-color: #FFC107;
}


So progress styles aren't being picked up on the page because they are changed into this format. How can I avoid this or have React change the class names appropriately?




If I removed this from my webpack config:

{
test: /\.css$/,
loader: 'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]'
}


Line it says that it can't find the css file but the path it errors out on is valid.




Webpack config for good measure:

'use strict';

var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
devtool: 'eval-source-map',
entry: [
'webpack-hot-middleware/client?reload=true',
path.join(__dirname, 'public/app/main.js')
],
output: {
path: path.join(__dirname, '/dist/'),
filename: '[name].js',
publicPath: '/'
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/app/index.html',
inject: 'body',
filename: 'index.html'
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
],
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
"presets": ["react", "es2015", "stage-0", "react-hmre"]
}
}, {
test: /\.json?$/,
loader: 'json'
}, {
test: /\.css$/,
loader: 'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]'
}]
}
};

Answer

Your config currently uses css-modules. To disable it change 'style!css?modules&localIdentName=[name]---[local]---[hash:base64:5]' to 'style!css' in the loader for css files.

Comments