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
490
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
410
Reactを段階的に覗いてみる
ytaisei
3
2.1k
Reactのトランジションを覗いてみる
ytaisei
1
2.6k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
530
React19で状態管理はどう変わるか
ytaisei
2
230
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
ぼっちではじめた登壇が「51名」「241件」の発信に化けた
subroh0508
1
240
【Snowflake Summit 2026 Recap!!】Snowflake Summit Deep Dive: Security & Governance
civitaspo
1
270
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.5k
Agent Skills設計で柔軟性と硬さのバランスが難しい話
nassy20
0
140
エラーバジェットのアラートのタイミングを考える.pdf
kairim0
0
170
脱SaaS!FDEを支えるプロビジョニングと分離設計
knih
0
240
AWS Security Agent といっしょに脅威モデリングをやってみよう
amarelo_n24
1
180
Bucharest Tech Week 2026 - Guardians of the Cloud-Native Galaxy
edeandrea
PRO
0
120
日本 Fintech 未来予測レポート 2027〜2028年(手動編集版)
8maki
1
2.5k
ザ・データベース、MySQL ~ OSC 2026 Sendai ~
sakaik
0
140
自分が詳しくない領域でAIを使う #プロヒス2026
konifar
13
5.3k
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
410
Featured
See All Featured
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
600
Embracing the Ebb and Flow
colly
88
5.1k
Believing is Seeing
oripsolob
1
150
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
210
Paper Plane
katiecoart
PRO
1
51k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Rails Girls Zürich Keynote
gr2m
96
14k
Evolving SEO for Evolving Search Engines
ryanjones
0
220
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
180
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