Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
linaria: Zero-Runtime CSS in JS
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
petamoriken / 森建
July 31, 2020
Programming
2.5k
2
Share
linaria: Zero-Runtime CSS in JS
社内エンジニア勉強会
petamoriken / 森建
July 31, 2020
More Decks by petamoriken / 森建
See All by petamoriken / 森建
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
230
Module Harmony
petamoriken
3
910
Denoでフロントエンド開発 2025年春版 / Frontend Development with Deno (Spring 2025)
petamoriken
1
1.6k
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
640
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
320
フロントエンドの標準仕様をどう追っているか / How I follow the frontend standards specs
petamoriken
4
2.7k
ECMAScript、Web標準の型はどう管理されているか / How ECMAScript and Web standards types are maintained
petamoriken
3
640
DOM Observable
petamoriken
1
350
Deno に Web 標準 API を実装する / Implementing Web standards API to Deno
petamoriken
0
810
Other Decks in Programming
See All in Programming
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
210
Getting more out of Maven
mlvandijk
0
110
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
380
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
270
Feature Toggle は捨てやすく使おう
gennei
0
590
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
1
110
tRPCの概要と少しだけパフォーマンス
misoton665
2
170
クラウドネイティブなエンジニアに向ける Raycastの魅力と実際の活用事例
nealle
2
180
PDI: Como Alavancar Sua Carreira e Seu Negócio
marcelgsantos
0
120
SkillがSkillを生む:QA観点出しを自動化した
sontixyou
6
3.4k
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
220
AI-DLC Deep Dive
yuukiyo
8
3.5k
Featured
See All Featured
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
270
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
160
Prompt Engineering for Job Search
mfonobong
0
270
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
180
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
The agentic SEO stack - context over prompts
schlessera
0
740
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
190
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Statistics for Hackers
jakevdp
799
230k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
340
Transcript
linaria Zero-Runtime CSS in JS pixiv Inc. petamoriken 2020.7.31
2 自己紹介まわり • 主にフロントエンドエンジニア • ECMAScript や WHATWG DOM を追うのが好き
• iOSDC Japan 2020 のサイト制作を担当しました petamoriken 課題解決部
3 HTML(JSX) と CSS の連携 • HTML(JSX) と CSS ファイルが分かれたタイプ
◦ BEM によるクラス管理 ◦ CSS Modules • CSS in JS ◦ styled-components / emotion ◦ jss
4 HTML(JSX) と CSS の連携 • HTML(JSX) と CSS ファイルが分かれたタイプ
◦ BEM によるクラス管理 ◦ CSS Modules • CSS in JS ◦ styled-components / emotion ◦ jss
const StyledButton = styled.button` color: blue; width: ${(props) => props.width}px;
`; <StyledButton width={50} /> styled-components / emotion 5 JSX HTML (レンダリング後) <button style="color: blue; width: 50px;">
6 styled-components / emotion について • 利点 ◦ CSS との連携を考えなくて良くなる
• 問題点 ◦ JS のランタイムで実行されるためパフォーマンスに問題がある スタイル付けされたCSS-in-JS実装は、スタイル付けされていないバージョンと比べ て50%以上もレンダリングに時間がかかるように見えた。 https://www.infoq.com/jp/news/2020/01/css-cssinjs-performance-cost/ ◦ ランタイムに stylis.js を使っていてカスタマイズしづらい
7
const StyledButton = styled.button` color: blue; width: ${(props) => props.width}px;
`; <StyledButton width={50} /> linaria 8 JSX .abcd1234 { color: blue; width: var(--abcd1234-0); } CSS <button class="abcd1234" style="--abcd1234-0: 50px;"> HTML (レンダリング後)
9 linaria について • 利点 ◦ パフォーマンスの問題を解決 ◦ コンパイル時に PostCSS
によるカスタマイズが可能 • 問題点 ◦ IE 11 非対応 ◦ ランタイムで styled-components / emotion ほどの柔軟性はない css prop が使えない / CSS プロパティの出し分けが出来ない
const StyledButton = styled.button` border-radius: 3px; ${(props) => props.large ?
css` padding: 0.5em 2em; font-size: 2em; ` : css` padding: 0.25em 1em; font-size: 1em; `} `; styled-components / emotion 10
const StyledButton = styled.button` border-radius: 3px; padding: 0.25em 1em; font-size:
1em; &[data-large] { padding: 0.5em 2em; font-size: 2em; } `; linaria 11
12 linaria を使ってみた所感 • styled-components / emotion とほとんど同じ書き方が可能 ◦ コンパイル時に
CSS が静的解析できないといけないことに注意 ◦ 書いていて特に困ることはなかった • まだまだ発展途上なため、即採用するものではなさそう ◦ Next.js には 1.x.x が使えないため 2.0.0-alpha.5 を使うことになる