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
440
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
210
Reactを段階的に覗いてみる
ytaisei
3
1.8k
Reactのトランジションを覗いてみる
ytaisei
1
2.5k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
400
React19で状態管理はどう変わるか
ytaisei
2
190
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
_第4回__AIxIoTビジネス共創ラボ紹介資料_20251203.pdf
iotcomjpadmin
0
140
20251222_サンフランシスコサバイバル術
ponponmikankan
2
150
Bedrock AgentCore Memoryの新機能 (Episode) を試してみた / try Bedrock AgentCore Memory Episodic functionarity
hoshi7_n
2
2.1k
2025年のデザインシステムとAI 活用を振り返る
leveragestech
0
400
Strands Agents × インタリーブ思考 で変わるAIエージェント設計 / Strands Agents x Interleaved Thinking AI Agents
takanorig
6
2.3k
Amazon Bedrock Knowledge Bases × メタデータ活用で実現する検証可能な RAG 設計
tomoaki25
6
2.6k
2025年の医用画像AI/AI×medical_imaging_in_2025_generated_by_AI
tdys13
0
160
Introduce marp-ai-slide-generator
itarutomy
0
150
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
9.9k
AWSに革命を起こすかもしれない新サービス・アップデートについてのお話
yama3133
0
520
Authlete で実装する MCP OAuth 認可サーバー #CIMD の実装を添えて
watahani
0
220
AI時代のワークフロー設計〜Durable Functions / Step Functions / Strands Agents を添えて〜
yakumo
3
2.4k
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
990
Automating Front-end Workflow
addyosmani
1371
200k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
A designer walks into a library…
pauljervisheath
210
24k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
53
47k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
280
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
320
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
78
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
The Limits of Empathy - UXLibs8
cassininazir
1
190
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