Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
BunがCommonJSをサポートする理由
Search
ytaisei
March 27, 2024
Technology
2
430
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
200
Reactを段階的に覗いてみる
ytaisei
3
1.8k
Reactのトランジションを覗いてみる
ytaisei
1
2.5k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
390
React19で状態管理はどう変わるか
ytaisei
2
180
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
10
2.4k
TanStack Routerで型安全かつ効率的なルーティングを実現
ytaisei
4
2.4k
TanStack Router SPA開発の選択肢になるか(+TanStack Query)
ytaisei
2
1.6k
【2023】SWR vs TanStack Query
ytaisei
1
2.2k
Other Decks in Technology
See All in Technology
Snowflake導入から1年、LayerXのデータ活用の現在 / One Year into Snowflake: How LayerX Uses Data Today
civitaspo
0
1.6k
AgentCoreとStrandsで社内d払いナレッジボットを作った話
motojimayu
1
590
マイクロサービスへの5年間 ぶっちゃけ何をしてどうなったか
joker1007
17
7.3k
高度サイバー人材育成専科資料(前半)
nomizone
0
390
特別捜査官等研修会
nomizone
0
520
子育てで想像してなかった「見えないダメージ」 / Unforeseen "hidden burdens" of raising children.
pauli
2
310
Oracle Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
1
740
日本Rubyの会: これまでとこれから
snoozer05
PRO
5
220
ZOZOの独自性を生み出す「似合う4大要素」の開発サイクル
zozotech
PRO
0
110
Database イノベーショントークを振り返る/reinvent-2025-database-innovation-talk-recap
emiki
0
250
アプリにAIを正しく組み込むための アーキテクチャ── 国産LLMの現実と実践
kohju
0
170
フィッシュボウルのやり方 / How to do a fishbowl
pauli
2
340
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
400
GitHub's CSS Performance
jonrohan
1032
470k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
33
Building the Perfect Custom Keyboard
takai
1
660
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
680
RailsConf 2023
tenderlove
30
1.3k
Raft: Consensus for Rubyists
vanstee
141
7.2k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.2k
Faster Mobile Websites
deanohume
310
31k
Prompt Engineering for Job Search
mfonobong
0
120
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
850
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