我正在尝试获取 react-css-modules可以在使用 sass 的同时工作,但就是无法正常工作。我正在关注文档,此时它应该可以正常工作。
Scss 包含在 jsx 中
import home from "../../scss/pages/_home.scss"
export default React.createClass({
render() {
return <app-content styleName={home.home}>
}
/>
</app-content>;
}
})
webpack.config.js
{test: /\.scss$/, loaders: [
'style?sourceMap',
'css?sourceMap&modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]',
'resolve-url',
'sass?sourceMap']},
{ test: /\.css$/, loader: "style-loader!css-loader?sourceMap&modules" },
当然没有 js 错误,编译后以下内容将输出到我的元素:
<app-content stylename="src-client-scss-pages-____home__home___JTSxY"></app-content>
但是根本没有任何样式。
最佳答案
呃……
好吧,我想过删除这个问题,但我想如果它可以避免有人浪费 2 个小时来做这样一个愚蠢的简单事情,为什么不发布答案:
return <app-content class={home.home}>
从具有样式的元素上的 styleName
更改为直观和明显的答案:class
。
祝大家好运!
关于javascript - 将 react-css-modules 与 sass 一起使用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37647676/