简体   繁体   English

用css-module做出反应?

[英]using css-module with react?

The React: 反应:

/**
 * Created by pingfengafei on 16/11/28.
 */
import React from 'react';
import HeaderContainer from './HeaderContainer';
import NavContainer from './NavContainer';
import ContentContainer from './ContentContainer';

import CSSModules from 'react-css-modules';
import styles from  './HomePageContainer.less';

class HomePageContainer extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <div className="home-page-wrap-normal" styleName='home-page-wrap'>
        <HeaderContainer />
        <NavContainer />
        <ContentContainer>
          {this.props.children}
        </ContentContainer>
      </div>

    );
  }

}

export default CSSModules(HomePageContainer, styles, {allowMultiple: true});

The doom node : 末日节点: 在此输入图像描述

The css style: css风格:

在此输入图像描述

The webpack.config: webpack.config:

{
    test: /\.(le|c)ss$/,
    loader: "style!css?sourceMap&modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]!postcss!less"
}

I want to add css modules into my React project just like instagram with react-css-modules . 我想将css模块添加到我的React项目中,就像使用react-css-modules instagram一样。

But find 2 problems: 但找到2个问题:

1: Can I partly using css-module? 1:我可以部分使用css-module吗? The child nodes of HomePageContainer-home-page-wrap-Ql_jW all lose css style, and the same with home-page-wrap-normal . HomePageContainer-home-page-wrap-Ql_jW的子节点都失去了css样式,与home-page-wrap-normal

It seems that I should replace the className with sytleName in the whole project. 看来我应该在整个项目中用sytleName替换className。 Is there any way that I can chose where use styleName and className with both showing the correct css style. 有没有什么办法可以选择使用styleName和className来显示正确的css样式。

2:Can I open sourceMap in develop model? 2:我可以在开发模型中打开sourceMap吗? The class with base64 is unreadable, I need a sourceMap connecting original class name with compiled class name. 使用base64的类是不可读的,我需要一个连接原始类名和编译类名的sourceMap。

To answer your first question, you can use :global inside your css/less file in order to load the style as normal css. 要回答您的第一个问题,您可以在css / less文件中使用:global ,以便将样式加载为普通css。

Please see this: CSS Modules - exclude class from being transformed 请看这个: CSS模块 - 排除类被转换

To answer your second question, your class name in source map should be readable enough. 要回答第二个问题,源地图中的类名应该足够可读。 You can change the following to make it even more readable: 您可以更改以下内容以使其更具可读性:

localIdentName=[name]___[local]___[hash:base64:4]

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

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