I have the the following component, imported css and webpack config - clearly I have imported the relevant css module, but the connection between my react output className={css__main.container}
and the imported css-loader seems not to have been made by react - css_main.container is not mapping to .main__container___2MJY
(it returns undefined
and therefore react/webpack does not include in the output) - I'm sure, being new to css modules, I've just missed a step, can anyone point out what it might be? ("css-loader": "^0.28.11"
is installed in package.json).
import React from 'react';
import {Route, browserHistory, Switch, Link, BrowserRouter, HashRouter} from 'react-router-dom';
import css__main from "../css/main.css";
import NoMatch from "./no-match.js";
import ButtonLink from "../components/buttonLink.js";
import List from "./lists/list-base.js";
import Home from "./subs/home.js";
class Main extends React.Component {
render(){
console.log( JSON.stringify( css__main ));
//[["./src/css/main.css",".main__container___2MJY_{border:1px solid #d0d0d0;-moz-box-shadow:0 0 8px #d0d0d0;box-shadow:0 0 8px #d0d0d0;overflow:hidden;height:80vh;display:flex;flex-direction:column;justify-content:flex-start}.main__header___3ZGBv{color:#444;background-color:transparent;border-bottom:1px solid #d0d0d0;font-size:1.2em;height:65px;display:flex;flex-direction:row;align-items:stretch;justify-content:space-between;padding:15px 20px}",""]]
return (
<div id="container" className={css__main.container}>
<div className={css__main.header}>
Flix AB Testing
</div>
<HashRouter history={browserHistory}>
<Switch>
<Route exact path="/" component={Home}/>
<Route path="/active" component={List}/>
<Route path="/inactive" component={List}/>
<Route path="/expire" component={List}/>
<Route path="/delete" component={List}/>
<Route component={NoMatch}/>
</Switch>
</HashRouter>
</div>
);
};
}
export default Main;
importing this css (which I can output to the console as shown in code block above):
.container {
border: 1px solid #D0D0D0;
-moz-box-shadow: 0 0 8px #D0D0D0;
box-shadow: 0 0 8px #D0D0D0;
overflow: hidden;
height: 80vh;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.header {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 1.2em;
height: 65px;
display: flex;
flex-direction: row;
align-items: stretch;
justify-content: space-between;
padding: 15px 20px;
}
my webpack config. is as follows:
module.exports = {
entry: [
'./src/index.js'
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.css$/,
loader: 'css-loader',
options: {
minimize: true,
camelCase: 'dashes',
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx', '.css']
},
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'bundle.js'
},
devServer: {
contentBase: './dist'
}
};