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
390
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
150
Reactを段階的に覗いてみる
ytaisei
3
1.7k
Reactのトランジションを覗いてみる
ytaisei
1
2.2k
Deep Dive Into React 〜React Fiber Architectureについて〜
ytaisei
2
290
React19で状態管理はどう変わるか
ytaisei
2
170
TanStackで効率的なルーティングとデータ取得を実現
ytaisei
9
2.1k
TanStack Routerで型安全かつ効率的なルーティングを実現
ytaisei
4
2.2k
TanStack Router SPA開発の選択肢になるか(+TanStack Query)
ytaisei
2
1.5k
【2023】SWR vs TanStack Query
ytaisei
1
2.1k
Other Decks in Technology
See All in Technology
GA technologiesでのAI-Readyの取り組み@DataOps Night
yuto16
0
280
多野優介
tanoyusuke
1
470
GC25 Recap+: Advancing Go Garbage Collection with Green Tea
logica0419
1
430
20201008_ファインディ_品質意識を育てる役目は人かAIか___2_.pdf
findy_eventslides
1
530
ZOZOのAI活用実践〜社内基盤からサービス応用まで〜
zozotech
PRO
0
200
生成AI_その前_に_マルチクラウド時代の信頼できるデータを支えるSnowflakeメタデータ活用術.pdf
cm_mikami
0
120
LLM時代にデータエンジニアの役割はどう変わるか?
ikkimiyazaki
4
960
バイブコーディングと継続的デプロイメント
nwiizo
2
460
extension 現場で使えるXcodeショートカット一覧
ktombow
0
220
Access-what? why and how, A11Y for All - Nordic.js 2025
gdomiciano
1
120
Findy Team+のSOC2取得までの道のり
rvirus0817
0
380
Trust as Infrastructure
bcantrill
0
350
Featured
See All Featured
Writing Fast Ruby
sferik
629
62k
How to train your dragon (web standard)
notwaldorf
96
6.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Being A Developer After 40
akosma
91
590k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
The Pragmatic Product Professional
lauravandoore
36
6.9k
The Cost Of JavaScript in 2023
addyosmani
53
9k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.1k
Typedesign – Prime Four
hannesfritz
42
2.8k
A Tale of Four Properties
chriscoyier
160
23k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
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