Skip to content

Instantly share code, notes, and snippets.

@ThaddeusJiang
Last active August 6, 2018 06:30
Show Gist options
  • Save ThaddeusJiang/995f8140cdca998ca6b4f0e57403ff11 to your computer and use it in GitHub Desktop.
Save ThaddeusJiang/995f8140cdca998ca6b4f0e57403ff11 to your computer and use it in GitHub Desktop.
CSS Modules 入门

为什么需要CSS模块化?

CSS 问题:

  1. 全局污染
  2. 命名混乱
  3. JS CSS 无法共享变量 复杂的组件有时需要使用 JS 和 CSS 共同处理样式
  4. 代码压缩不彻底 因为全局污染问题,超长 class 名,无法压缩到极限。

使用

import styles from './table.css'

export default class CustomView extends React.Component {
    render() {
        return (
            <div className={styles.table}>
                <div className={styles.row}></div>
            </div>
        )
    }
}

渲染出来的组件

<div class="table__table___32osj">
    <div class="table__row___2w27N">
    </div>
</div>

优秀文章

camsong/blog#5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment