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
React+webpackのビルドを高速化
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Masashi Hirano
January 11, 2018
Programming
2k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
React+webpackのビルドを高速化
Osaka Mix Leap #4 - React でLTしました。
https://yahoo-osaka.connpass.com/event/75065/
Masashi Hirano
January 11, 2018
More Decks by Masashi Hirano
See All by Masashi Hirano
フロントエンド開発のためのブラウザ組み込みAI入門
masashi
7
5k
Protocol Buffers and Connect for Frontend Development
masashi
0
180
You may not need XXX in Node.js
masashi
5
2.1k
OSSとコミュニティを支える
masashi
1
2.3k
英語ができなかった自分達が、グローバルチーム立ち上げに挑戦!?
masashi
1
3.9k
フロントエンド開発のためのセキュリティ入門について
masashi
1
610
フロントエンド開発のためのセキュリティ入門
masashi
50
19k
Node.jsの2022年と未来 / Node.js in 2022 and Future
masashi
1
1.2k
Corepack ~Node.jsに追加されたパッケージマネージャーマネージャー~ / #tng37
masashi
3
13k
Other Decks in Programming
See All in Programming
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
370
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
540
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
150
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
220
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
150
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
110
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
170
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
110
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
230
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
240
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
150
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
140
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
225
10k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
390
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Thoughts on Productivity
jonyablonski
76
5.4k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Music & Morning Musume
bryan
47
7.4k
Heart Work Chapter 1 - Part 1
lfama
PRO
9
36k
Designing Powerful Visuals for Engaging Learning
tmiket
1
540
Code Review Best Practice
trishagee
74
20k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
190
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Building Adaptive Systems
keathley
44
3.2k
Transcript
React+webpackのビルドを高速化 Osaka Mix Leap (2018/01/11)平野昌士 / @shisama
{ "about": { "name": "Masashi Hirano", "works": "Weblio, Inc.", "twitter":
"@shisama_", "github": "shisama" } }
この発表の対象者 webpack使ってる方 JSのビルドに時間がかかるとお悩みの方 開発スピードをもっとあげたい方
仕事でReactを使ったSPAを開発して います
webpackを使ってビルドしています
webpackのビルド実行時間 1分もかかります
もっとビルド早くして開発スピードあ げたい
主にwebpackでしていること 複数ファイルを一つにバンドル babelでES2015+やReactを変換 minify
高速化前のwebpack.config module.exports = { // webpack.config.js 一部抜粋 plugins: [ new
webpack.optimize.UglifyJsPlugin(), ], module: { rules: [ { test: /\.(js|jsx)$/, use: 'babel-loader', }, ] }, };
ここからビルドの実行を高 速化していきます
高速化に使ったもの cacheDirectory DllPlugin
cacheDirectory
cacheDirectory babel‒loaderのオプション機能 babelの結果をキャッシュする デフォルトではoffになっています
cacheDirectoryの使いかた webpack.config内のbabel‒loaderにクエリを追加する だけ
cacheDirectoryの使いかた module.exports = { // webpack.config.js 一部抜粋 plugins: [ new
webpack.optimize.UglifyJsPlugin(), ], module: { rules: [ { test: /\.(js|jsx)$/, use: 'babel-loader?cacheDirectory', // cacheDirectory on }, ] }, };
ビルド実行時間 高速化前: 1分前後 cacheDirectory(初回): 1分前後 cacheDirectory(2回目以降): 40秒~50秒
DllPlugin
DllPlugin webpackのプラグイン 依存PKGだけバンドルしてファイル分割 →reactとかreact‒domとかを別ファイルにまとめる →分割するので、元のバンドルファイルは軽くなる →分割したファイル両方をhtmlで読み込む 依存PKGに変更が無ければDLLバンドルファイルの更 新は不要
DllPluginの使い方 DLLバンドル用のwebpack.configを用意 これまでのwebpack.config側でDLLバンドルの情報を 読み込む 分割したファイルをhtmlで読み込む
DLLバンドル用のwebpack.config const path = require('path'); const webpack = require('webpack'); module.exports
= { entry: { // 依存PKG 配列 指定 vendor: ['react', 'react-dom' /* 依存PKG */], }, output: { path: 'path/to/dist', filename: '[name].dll.js', library: '[name]', }, plugins: [ // DllPlugin manifest.json 吐 new webpack.DllPlugin({ path: 'path/to/dll/[name]-manifest.json'), name: '[name]', }), new webpack.optimize.UglifyJsPlugin(), ], resolve: { modules: [path.resolve(__dirname, 'src'), 'node_modules'], }, };
これまでのwebpack.config module.exports = { // webpack.config.js 一部抜粋 plugins: [ //
Dll 使 new webpack.DllReferencePlugin({ context: __dirname, // DLL manifest.json 指定 manifest: require('path/to/dll/vendor-manifest.json'), }), new webpack.optimize.UglifyJsPlugin(), ], module: { rules: [ { test: /\.(js|jsx)$/, use: 'babel-loader?cacheDirectory', // cacheDirectory on }, ] } };
分割したファイルをhtmlで読み込む <!-- DLL 先 読 込 --> <script src="./vendor.dll.js"></script> <!--
元 --> <script src="./index.bundle.js"></script>
ビルド実行時間 高速化前: 1分前後 cacheDirectory(2回目以降): 40~50秒 cacheDirectory+DllPlugin: 20秒前後
その他高速手段 ・happypack ・webpackのキャッシュ ・今回は効果が出ませんでした ・webpack#externals ・指定したPKGをバンドルに含めない ・依存PKGはCDNから取ってくる場合おすすめ ・parcel ・バズったやつ ・Blazing
fast。webpackよりかなりビルド早い ・no config ・webpackほど機能豊富ではない ・minifyが壊れていたりするらしい ・現状では導入は厳しそう
参考 ・ ・ ・ ・ ・ babel‒loader DllPlugin webpackのDLLバンドルを使ってビルドを速くする webpack時代の終わりとparcel時代のはじまり
parcelでバンドルしてみた & そのとき出会ったハマりどころまと め
宣伝
ご清聴ありがとうございました