简体   繁体   English

在sass中使用react-css-modules不起作用

[英]Using react-css-modules with sass not working

I am trying to get react-css-modules 's to work whilst using sass but just can't get it working. 我正在尝试使用sass来使react-css-modules正常工作,但无法使其正常工作。 I am following the documentation and it should just work at this point. 我正在关注文档,它现在应该可以正常工作。

Scss include in jsx jsx中包含的Scss

import home from "../../scss/pages/_home.scss"

export default React.createClass({

    render() {
        return <app-content styleName={home.home}>
              }
         />
        </app-content>;
    }
})

webpack.config.js 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" },

Of course there are no js errors and the following gets output to my elements once compiled: 当然没有js错误,编译后以下内容会输出到我的元素中:

<app-content stylename="src-client-scss-pages-____home__home___JTSxY"></app-content>

But there just aren't any styles at all. 但是,根本没有任何样式。

Urgh... 嗯...

Ok, I thought about deleting the question but thought maybe if it could save somebody wasting 2 hours for such a stupidly simple thing why not post the answer: 好的,我考虑过删除问题,但想想是否可以节省一个这样愚蠢的事情浪费2个小时的人,为什么不发布答案:

    return <app-content class={home.home}>

The change being from styleName on the element with the style to the intuitive and obvious answer: class . 从具有样式的元素上的styleName更改为直观而明显的答案: class

Good luck people! 祝大家好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM