Skip to content

Instantly share code, notes, and snippets.

@himanoa
Created October 1, 2019 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himanoa/9a6bf27e09b0d6001522c905203b8810 to your computer and use it in GitHub Desktop.
Save himanoa/9a6bf27e09b0d6001522c905203b8810 to your computer and use it in GitHub Desktop.
コンポーネント時代のcss現実バージョン
import React from "react"
import styled from "styled-components"
const Button = styled.div`
padding: 4px;
border: 1px solid #000;
`
export default React.memo(Button)
import React from "react"
import css from "void-css"
/*
void-cssは架空のモジュールで以下のような感じだと思ってください。実装は無でビルドした時にbabelで消し去られる記述です
declare module void-css {
css(style: string[]): void
export css
}
*/
css`
.button {
padding: 4px;
border: 1px solid #000;
}
`
const Button: React.FC<{}> = () => (
<div class=".button"></div>
)
export default React.memo(Button)
<div class="src_理想_button_1dxasdq"></div>
.src_理想_button_1dxasdq {
.button {
padding: 4px;
border: 1px solid #000;
}
}
@himanoa
Copy link
Author

himanoa commented Oct 1, 2019

なにがいいたいか

  • babel使ってjsからcss``で囲まれたブロックを抜き出してautoprefixerかけてcssファイルとして出力する
  • その際にcss-moduleっぽく一意なclass名に置換するやつ。
  • ついでにJSXで使ってるclassをcss-moduleっぽく一意なsuffixつけるやつ

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