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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
490
Reactを段階的に覗いてみる
ytaisei
3
2.2k
Reactのトランジションを覗いてみる
ytaisei
1
2.7k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
580
React19で状態管理はどう変わるか
ytaisei
2
240
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
10
2.6k
TanStack Routerで型安全かつ効率的なルーティングを実現
ytaisei
4
2.6k
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
Hub & Spoke 環境のネットワークルーティングを分解してみる
tsuyataku
1
500
Self Healing Rollouts: Automating Production Fixes with Agentic AI
kdubois
0
120
顧客の要望は2次情報である 〜アンテナを張るFDEの構造論〜
noriakioji
5
1.1k
AI時代のキョウソウ戦略
ystk
2
120
ClaudeCodeでセキュリティ監視業務を半自動化_1年の運用でわかったAIに任せる設計の5つのポイント
kintotechdev
4
1k
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.5k
Bet AI Day 2026丨Agentは、「金融」という巨大産業の何を変えられるのか
layerx
PRO
0
510
VPCでもFloatingIPを使いたいんだ
y_kotani
1
140
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
12
87k
データエンジニアの困りごとをDevinと一緒に解消する
10xinc
2
200
生成AI時代の クレデンシャルとパーミッション設計
nrinetcom
PRO
3
380
Azure App Service / Container Apps の組み込み認証
kuniteru
0
120
Featured
See All Featured
The Invisible Side of Design
smashingmag
301
52k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
300
How STYLIGHT went responsive
nonsquared
100
6.3k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
550
Amusing Abliteration
ianozsvald
1
280
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Crafting Experiences
bethany
1
270
HDC tutorial
michielstock
2
830
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
220
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
550
The Pragmatic Product Professional
lauravandoore
37
7.4k
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