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
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
380
Reactを段階的に覗いてみる
ytaisei
3
2.1k
Reactのトランジションを覗いてみる
ytaisei
1
2.6k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
520
React19で状態管理はどう変わるか
ytaisei
2
230
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
10
2.6k
TanStack Routerで型安全かつ効率的なルーティングを実現
ytaisei
4
2.5k
TanStack Router SPA開発の選択肢になるか(+TanStack Query)
ytaisei
2
1.7k
【2023】SWR vs TanStack Query
ytaisei
1
2.3k
Other Decks in Technology
See All in Technology
Agentic AI時代における メルカリのAIガバナンスとガードレール実装
naoichihara
16
17k
さきさん文庫の書籍ができるまで
sakiengineer
0
310
Anthropic AIネイティブ・スタートアップ構築のプレイブック を理解する
nagatsu
0
220
電子辞書Brainをネットに繋げてみた(自力編)
raspython3
0
310
【ハノーバーメッセ振り返りイベントat名古屋】データは集約からAI起点の収集に ~組織内・組織間でのデータ連携~
tanakaseiya
0
150
海外カンファレンス「JavaOne」参加レポート ユーザー系IT企業における目的・成果/JavaOne Report Purpose and Results in the User IT Company
muit
0
110
AI Adaptable なテストを整える工夫 / Ways to Make Your Tests AI-Adaptable
bitkey
PRO
2
170
GitHub Copilot のこれまでとこれから: From Copilot to Collaborative Agents
yuriemori
1
230
コードレビューを制するチームがソフトウェアデリバリーのフローを制す / Beyond Code Review: Distributing Its Responsibilities Across the SDLC
mtx2s
1
430
Java正規表現エンジン(NFA)の仕組みと パフォーマンスを維持するための最適化手法
takeuchi_132917
0
150
Javaで学ぶSOLID原則
negima
1
240
AI時代の私の技術インプットとアウトプット術
tonkotsuboy_com
15
7.7k
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
160
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
The Spectacular Lies of Maps
axbom
PRO
1
770
Game over? The fight for quality and originality in the time of robots
wayneb77
1
180
Context Engineering - Making Every Token Count
addyosmani
9
920
Heart Work Chapter 1 - Part 1
lfama
PRO
7
36k
For a Future-Friendly Web
brad_frost
183
10k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
330
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
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