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
2
460
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
260
Reactを段階的に覗いてみる
ytaisei
3
2k
Reactのトランジションを覗いてみる
ytaisei
1
2.6k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
480
React19で状態管理はどう変わるか
ytaisei
2
200
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
10
2.5k
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
君はジョシュアツリーを知っているか?名前をつけて事象を正しく認識しよう / Do you know Joshua Tree?
ykanoh
4
140
SSoT(Single Source of Truth)で「壊して再生」する設計
kawauso
2
380
Phase06_ClaudeCode実践
overflowinc
0
2.2k
Embeddings : Symfony AI en pratique
lyrixx
0
350
Physical AI on AWS リファレンスアーキテクチャ / Physical AI on AWS Reference Architecture
aws_shota
1
170
Kubernetesの「隠れメモリ消費」によるNode共倒れと、Request適正化という処方箋
g0xu
0
140
ThetaOS - A Mythical Machine comes Alive
aslander
0
200
Zephyr(RTOS)でOpenPLCを実装してみた
iotengineer22
0
130
FlutterでPiP再生を実装した話
s9a17
0
210
Phase04_ターミナル基礎
overflowinc
0
2.6k
Navigation APIと見るSvelteKitのWeb標準志向
yamanoku
2
120
スケールアップ企業でQA組織が機能し続けるための組織設計と仕組み〜ボトムアップとトップダウンを両輪としたアプローチ〜
qa
0
350
Featured
See All Featured
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.2k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
210
The Cost Of JavaScript in 2023
addyosmani
55
9.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Darren the Foodie - Storyboard
khoart
PRO
3
3k
sira's awesome portfolio website redesign presentation
elsirapls
0
200
The Curse of the Amulet
leimatthew05
1
11k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.5k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
490
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
280
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
470
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
150
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