【发布时间】:2017-01-24 06:10:56
【问题描述】:
一切看起来都很好,没有错误,但是页面上的元素仍然没有样式。
webpack.config.js
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]')
},
plugins: [
new ExtractTextPlugin('app.css', {
allChunks: true
}),
],
Layout.js
import React, { Component } from 'react';
import InteractiveMap from './InteractiveMap';
import Header from './header';
import Navigation from './navigation';
import CSSModules from 'react-css-modules';
import styles from './Layout.css';
class Layout extends Component {
render() {
return (
<div>
<div className={styles.mapContainer}>
<InteractiveMap />
</div>
<div>
<Header className={styles.header}>
<Navigation menuItems={menuItems}/>
</Header>
</div>
</div>
);
}
}
export default CSSModules(Layout, styles);
Layout.css
//testing
.mapContainer: {
padding: 0;
background-color: black;
height: 100%;
color: yellow;
}
.header {
color: yellow;
background-color: blue;
}
编译好的 app.css
.Layout__mapContainer___3yH5h: {
padding: 0;
background-color: black;
height: 100%;
color: yellow;
}
.Layout__header___2kJ4F {
color: yellow;
background-color: blue;
}
正如您在图片中看到的那样,生成了类并应用于元素,但页面上没有显示任何内容。 image
【问题讨论】:
-
您对此有什么解决方案吗?我也面临同样的问题。
标签: css reactjs webpack react-css-modules