Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PuppeteerでいらないCSSを消す
Search
Hiroyuki ANAI
June 19, 2019
Programming
29k
23
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PuppeteerでいらないCSSを消す
@pirosikick の発表資料です。
https://mentaico-js.connpass.com/event/132416/
Hiroyuki ANAI
June 19, 2019
Transcript
22 slides
͍Βͳ͍$44Λ 1VQQFUFFSͰফ͢ !QJSPTJLJDL 8FC (PPHMF*0ͷ8FCΛ·ͱΊΔձ
ࣗݾհ w !QJSPTJLJDL w αΠϘζגࣜձࣾ ϑϩϯτΤϯυΤΩεύʔτνʔϜ w طʹ͝ଘͩͱࢥ͍·͕͢ɺ ࡢɺঁ͕࢈·Ε·ͨ͠!
࠷͍ۙͬͯΔࣄ w ڊେͳ$44ͷTUZMFEDPNQPOFOUTԽ w ສߦ͋Δ͕ɺશͯͷελΠϧ͕ඞཁͳΘ͚Ͱͳ͍ w ͦͷଞͷ w NJODTTͱ͍͏֦ுࢠͳͷʹѹॖ͞Ε͍ͯͳ͍ w
CPPUTUSBQGPOUBXFTPNFͷελΠϧΛ্ॻ͖͍ͯ͠Δ w ৄࡉ͕ߴ͗͢ΔελΠϧ͕݁ߏ͋ΔFUD
Ͳ͏ઓ͑Α͍ͷ͔ Θ͔ΒΜ
.PEFSO8FC5FTUJOHBOE"VUPNBUJPOXJUI1VQQFUFFS IUUQTXXXZPVUVCFDPNXBUDI W.CO"5-$V,* 1VQQFUFFSͰ +4ɾ$44ͷΧόϨοδ͕ औΕ·͢
͜ͷػೳΛ͑ ͬͯͳ͍ελΠϧΛ ୳͠ग़ͤΔͷͰʁ
1VQQFUFFSͰ $44ͷΧόϨοδΛऔಘ const puppeteer = require('puppeteer'); (async () => {
// ブラウザの起動 const browser = await puppeteer.launch(); const page = await browser.newPage(); // カバレッジの収集を開始 await page.coverage.startCSSCoverage(); // カバジッジを取りたいページを徘徊 await page.goto(…); … // カバレッジの収集を終了 const cssCoverage = await page.coverage.stopCSSCoverage(); … })();
QVQQFUFFSUPJTUBOCVMͰ OZD͕ॲཧՄೳͳϑΥʔϚοτʹม const pti = require('puppeteer-to-istanbul'); // .nyc_output/*を生成 pti.write(cssCoverage);
)5.-ܗࣜͷϨϙʔτΛੜ w OQYOZDSFQPSUSFQPSUFSIUNM w DPWFSBHFҎԼʹ)5.-Λग़ྗ w PQFODPWFSBHFJOEFYIUNM
εΫγϣషΔ
खಈͰফ͢ͷਏͦ͏ ΧόϨοδ͔ΒࣗಈͰ ফͤͳ͍͔ʁ
OZD@PVUQVUͷத w PVUKTPO w ֤ϑΝΠϧͷΧόϨοδใ w KT DTTKT w $44ϑΝΠϧͦͷͷ
w ֦ுࢠ͕KTʹͳ͍ͬͯΔͷṖ
OZD@PVUQVUPVUKTPOͷ TϑΟʔϧυ͕͑ͦ͏ // .nyc_output/out.jsonの構造 { "ファイルパス": { "path": "ファイルパス", "s":
{ "行数": 0 or 1 // 1の場合、カバレッジ有り … }, … }, … }
ෆཁͳߦΛফ͢ॲཧʢΠϝʔδʣ const fs = require('fs'); const readline = require('readline'); //
out.jsonのsフィールドから不要な行を消す処理のイメージ const removeUnusedLines = (filePath, s) => new Promise(resolve => { const reader = readline.createInterface({ input: fs.createReadStream(filePath) }); let currentLine = 0; const lines = []; // ファイルから1行ずつ読む reader.on('line', line => { // カバレッジがある行を残す if (s[currentLine++]) { lines.push(line); } }); reader.on('close', () => resolve(lines)); });
݁Ռ w ΧόϨοδ͕͔͠ͳ͔ͬͨ w ສߦˠߦ w ·ͩଟ͍͕ΪϦΪϦઓ͑Δߦʹͳͬͨ
ϋϚͬͨͱ͜Ζ
QBHFHPUPͷͨͼʹ ΧόϨοδ͕Ϧηοτ͞ΕΔ w ҎԼͷΑ͏ʹରॲ w HPUPຖʹΧόϨοδΛੜ w QUPJXSJUFҰͭͷΧόϨοδ͔͠ड͚͚ͳ͍ͷͰ w ෳͷΧόϨοδΛϚʔδͯ͠
ҰͭͷΧόϨοδΛੜ
QVQQFUFFS͕ग़ྗ͢Δ ΧόϨοδͷߏ [ { url: "ファイルのURL", text: "ファイルの中身", ranges: [
// カバレッジの開始位置・終了位置の配列 { start: 0, end: 100 }, … ] }, … ]
ෳͷΧόϨοδΛϚʔδ { url: "ファイルA", text: "…", ranges: [ { start:
0, end: 100 }, { start: 201, end: 300 } ] } { url: "ファイルA", text: "…", ranges: [ { start: 101, end: 200 }, { start: 250, end: 350 } ] } ΧόϨοδͦͷ ΧόϨοδͦͷ { url: "ファイルA", text: "…", ranges: [ { start: 0, end: 100 }, { start: 101, end: 200 }, { start: 201, end: 350 } ] }
ΧόϨοδ͕ൃੜ͠ͳ͍ w !NFEJBએݴɺ!GPOUGBDFએݴʹ ΧόϨοδ͕ൃੜ͠ͳ͍ w *TTVFʹొ͞Ε͍͕ͯͨόά͔༷͔͔Βͳ͍ w ҎԼͷΑ͏ʹରॲ w !GPOUGBDFએݴΧόϨοδ͋Γͳؔ͠ΘΒͣ͢
w !NFEJBએݴͷελΠϧʹΧόϨοδ͕͋Δ߹ ͢
͓ΘΓ w 1VQQFUFFS&&ςετҎ֎ͷ͍ํͰ͖Δʂ w ࠷ऴతʹεΫγϣΛऔ͓͍ͬͯͯ ը૾ࠩΛग़ͤΔΑ͏ʹͯ͠ΑΓ࣮֬ʹෆཁͳελΠϧΛ ফͤΔΑ͏ʹͨ͠
͋Γ͕ͱ͏ ͍͟͝·ͨ͠
More Decks by Hiroyuki ANAI
See All by Hiroyuki ANAI
安心して変更できるWebフロントエンドの作り方
pirosikick
7
3.6k
書き換えて学ぶTemporal #fukts
pirosikick
2
530
fukuoka.ts #3 社内でESLintの共通設定を配りたい2025年春版
pirosikick
3
530
compilerOptions、全部読んだ
pirosikick
1
330
Step Functionsの設計時に知っておいたほうがいいかもしれないこと
pirosikick
0
590
Go言語による並行処理「4.4 orチャネル」の図
pirosikick
0
530
サイボウズWebフロントエンド脱レガシーの今までとこれから
pirosikick
6
17k
@cybozu/eslint-configから学ぶ、全社共通ESLint configの運用
pirosikick
4
1.9k
Web Share Target API #w3fukuoka
pirosikick
0
760
Other Decks in Programming
See All in Programming
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
210
はじめてのKubernetesコントリビューション
nasa9084
0
330
Debian JP Projectのサーバー構成
uwabami
1
190
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
320
高速開発を止めずに 性能を上げる Flyleのシステム刷新と改善の歴史
azihsoyn
0
110
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
410
Distance field of Julia set
kinakomoti321
0
330
数行の変更でDockerビルドを最大91%高速化~GitLab CIの実行基盤を社内40リポジトリに展開するまで~
picopico
3
1.2k
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
700
AIコーディングをセッションで終わらせない: PHPライブラリ開発におけるコンテキスト承継設計
ickx
0
110
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
120
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
470
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.7k
Building an army of robots
kneath
307
47k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Discover your Explorer Soul
emna__ayadi
2
1.4k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
2
4.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Balancing Empowerment & Direction
lara
6
1.4k
Leo the Paperboy
mayatellez
11
2.5k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
480
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
620
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k