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
BunがCommonJSをサポートする理由
Search
ytaisei
March 27, 2024
Technology
2
460
BunがCommonJSをサポートする理由
フロントエンドTechCafe〜春のBun祭りLT会〜にて使用した資料。
参考資料:
https://bun.sh/blog/commonjs-is-not-going-away
ytaisei
March 27, 2024
Tweet
Share
More Decks by ytaisei
See All by ytaisei
TanStack Routerを新規プロダクトで1年間運用してみた結果
ytaisei
1
250
Reactを段階的に覗いてみる
ytaisei
3
1.9k
Reactのトランジションを覗いてみる
ytaisei
1
2.5k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
460
React19で状態管理はどう変わるか
ytaisei
2
200
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
10
2.5k
TanStack Routerで型安全かつ効率的なルーティングを実現
ytaisei
4
2.4k
TanStack Router SPA開発の選択肢になるか(+TanStack Query)
ytaisei
2
1.7k
【2023】SWR vs TanStack Query
ytaisei
1
2.2k
Other Decks in Technology
See All in Technology
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
4
22k
AI活用を"目的"にしたら、データの本質が見えてきた - Snowflake Intelligence実験記 / chasing-ai-finding-data
pei0804
0
680
Introduction to Bill One Development Engineer
sansan33
PRO
0
370
ローカルでLLMを使ってみよう
kosmosebi
0
200
OCI技術資料 : 外部接続 VPN接続 詳細
ocise
1
10k
NW構成図の自動描画は何が難しいのか?/netdevnight3
corestate55
2
470
マイグレーションガイドに書いてないRiverpod 3移行話
taiju59
0
270
ソフトウェアアーキテクトのための意思決定術: Create Decision Readiness—The Real Skill Behind Architectural Decision
snoozer05
PRO
22
6.3k
俺の失敗を乗り越えろ!メーカーの開発現場での失敗談と乗り越え方 ~ゆるゆるチームリーダー編~
spiddle
0
350
もう怖くないバックグラウンド処理 Background Tasks のすべて - Hakodate.swift #1
kantacky
0
120
Amazon Bedrock AgentCoreでブラウザ拡張型AI調査エージェントを開発した話 (シングルエージェント編)
nasuvitz
2
120
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
43k
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.4k
Raft: Consensus for Rubyists
vanstee
141
7.3k
AI: The stuff that nobody shows you
jnunemaker
PRO
3
330
ラッコキーワード サービス紹介資料
rakko
1
2.4M
Deep Space Network (abreviated)
tonyrice
0
78
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
64
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
190
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
130
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
160
Transcript
BunがCommonJS をサポートする理由 ytaisei(安井大晟)
ytaisei(安井大晟) • フロントエンド • 24卒CyberAgent • 株式会社AI Shift
Bunあまり知らない... ⇨LT応募する ⇨リサーチする
「CommonJS is not going away」というブログを発見 • 公式のブログ • 2023年6月なので少し古いかも
CJSとESM • CommonJS • ES Modules • require/exportsを使用 • 同期的にロード
• 元々サーバでの使用が想定されていた • import/exportを使用 • 同期・非同期でのロードに対応 • ブラウザでもネイティブサポート
CJSとESM • CommonJS • ES Modules • require/exportsを使用 • 同期的にロード
• 元々サーバでの使用が想定されていた • import/exportを使用 • 同期・非同期でのロードに対応 • ブラウザでもネイティブサポート 新規のプロジェクトであれば ESMが推奨
では、なぜCJSをサポートする?
public npm registryにおけるCommonJSの割合 • ESMの割合がかなり増えている • 依然としてCJSが67%以上 参考:https://github.com/wooorm/npm-esm-vs-cjs?tab=readme-ov-file
CommonJSの存在を尊重する姿勢
CommomJSの方がモジュールのLoadが早いケースも
CommomJSの方がモジュールのLoadが早いケースも 手元のベンチマークではCJSの方が約1.5倍早かった
Bunでは同一File内で importとrequireを使用可能 (CJSとESMの共存が可能)
結論 • BunではCJSとESMのどちらもサポートしている • CJS自体のメリットも含めて、 CJSを尊重する姿勢が記事から伺えた
Thanks!!! X: ytaisei_ Zenn: @taisei-13046