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
510
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
470
Reactを段階的に覗いてみる
ytaisei
3
2.1k
Reactのトランジションを覗いてみる
ytaisei
1
2.7k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
560
React19で状態管理はどう変わるか
ytaisei
2
240
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
10
2.6k
TanStack Routerで型安全かつ効率的なルーティングを実現
ytaisei
4
2.5k
TanStack Router SPA開発の選択肢になるか(+TanStack Query)
ytaisei
2
1.8k
【2023】SWR vs TanStack Query
ytaisei
1
2.3k
Other Decks in Technology
See All in Technology
ブラウザ研修 2026
recruitengineers
PRO
6
990
【AG-UI × A2UI × MCP Apps】Generative UIをやさしく解説する
nrinetcom
PRO
1
120
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
17
7.3k
モノリス Rails でも日中に rails db:migrate を走らせたい! / Daytime rails db:migrate on Monolithic Rails!
euglena1215
4
580
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
Model Studio CLI × Token Plan
maigo999
0
180
老害フォレンジッカーはAI羊の夢を見るか?
tadmaddad
0
330
Goでデータパイプラインを作ろう
sansantech
PRO
1
450
Genie Codeハンズオン基礎編
taka_aki
1
120
Bill One 開発エンジニア 紹介資料
sansan33
PRO
7
19k
ラジオの科学
frievea
0
310
Digitization部 紹介資料
sansan33
PRO
2
7.7k
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
187
22k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
630
The Curse of the Amulet
leimatthew05
2
14k
Design in an AI World
tapps
1
280
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.7k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
460
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