前端模塊化以後,CSS也能向模塊同樣導入, 以前提倡JS 與CSS分離,如今JS和CSS混合的方式又開始流行了。css
CSS與JS分離
CSS Modules前端
- No more conflicts 沒有名稱衝突
- No global scope
- Composing from other files
- Composing from global class names
![compose from other files compose from other files](http://static.javashuo.com/static/loading.gif)
![compose from global compose from global](http://static.javashuo.com/static/loading.gif)
CSS in JSS
JSS
- Theming 利用 ThemeProvider 和 theme 封裝組件
- withTheme
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
- ThemeProvider
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
Benefitsreact
- Theming support out of the box.
- Critical CSS extraction.
- Lazy evaluation - sheet is created only when component will mount.
- Auto attach/detach - sheet will be rendered to the DOM when component is about to mount and will be removed when no element needs it.
- A Style Sheet gets shared between all elements.
Styled-component
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
- styled-components has full theming support by exporting
- a <ThemeProvider> wrapper component.
- Function themes
- Getting the theme without styled components
![clipboard.png clipboard.png](http://static.javashuo.com/static/loading.gif)
styled-component 上提供了個對比 https://github.com/styled-com...git
參考文獻
https://glenmaddern.com/artic...
https://speakerdeck.com/vjeux...
http://www.alloyteam.com/2017...
https://hackernoon.com/the-co...github