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
480
2
Share
BunがCommonJSをサポートする理由
フロントエンドTechCafe〜春のBun祭りLT会〜にて使用した資料。
参考資料:
https://bun.sh/blog/commonjs-is-not-going-away
ytaisei
March 27, 2024
More Decks by ytaisei
See All by ytaisei
TanStack Routerを新規プロダクトで1年間運用してみた結果
ytaisei
1
360
Reactを段階的に覗いてみる
ytaisei
3
2k
Reactのトランジションを覗いてみる
ytaisei
1
2.6k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
510
React19で状態管理はどう変わるか
ytaisei
2
210
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
10
2.6k
TanStack Routerで型安全かつ効率的なルーティングを実現
ytaisei
4
2.5k
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
100マイクロサービスのTerraform/Kubernetes管理地獄から抜け出すためのAI活用術
markie1009
0
130
知ってた?JavaScriptの"正しさ"を検証するテストが5万以上もあること(Test262)
riyaamemiya
1
190
SREの仕事は「壊さないこと」ではなくなった 〜自律化していくシステムに、責任と判断を与えるという価値〜 / 20260515 Naoki Shimada
shift_evolve
PRO
1
130
ハーネスエンジニアリング入門
hatyibei
0
120
AIエージェントの支払い基盤 AgentCore Payments概要
kmiya84377
2
170
AIが盛んな時代に 技術記事を書き始めて起きた私の中での小さな変化
peintangos
0
370
Oracle Cloud Infrastructure presents managed, serverless MCP Servers for Oracle AI Database
thatjeffsmith
0
220
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
100k
『生成AI時代のクレデンシャルとパーミッション設計 — Claude Code を起点に』の執筆企画
takuros
3
2.3k
AIの揺らぎに“コシ”を与える階層化品質設計
ickx
0
270
毎日の作業を Claude Code 経由にしたら、 ノウハウがコードになった
kossykinto
1
1.3k
ボトムアップの改善の火を灯し続けろ!〜支援現場で学んだ、消えないための3つの打ち手〜 / 20260509 Kazuki Mori
shift_evolve
PRO
2
640
Featured
See All Featured
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
240
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
350
The Language of Interfaces
destraynor
162
26k
Chasing Engaging Ingredients in Design
codingconduct
0
190
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
340
Information Architects: The Missing Link in Design Systems
soysaucechin
0
920
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
150
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Docker and Python
trallard
47
3.8k
Paper Plane
katiecoart
PRO
1
50k
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