スコープホイスティングとは何か
スコープホイスティングは、各モジュールを個別の関数クロージャでラップするのではなく、複数のモジュールを 1 つの共有スコープにまとめるバンドリング手法です。それらのラッパーを取り除くことで実行時のオーバーヘッドが減り、デッドコード除去のような他の最適化がモジュールの境界を越えて機能できるようになります。モジュール連結と呼ばれることもあります。
なぜ重要か
モジュールごとのラッパー関数は、起動を遅くするバイト数と間接参照を追加します。モジュールを単一のスコープにホイスティングすることで、特に小さなモジュールが多数関わる場合に、より小さく高速な bundle が生成されます。
関連ガイド
Tree Shaking - CI/CD Glossary DefinitionTree shaking removes code that is never imported or used from a bundle by analyzing the module graph, shrinki…
What Is Dead Code Elimination?Dead code elimination is a compiler or bundler optimization that removes code which can never affect the prog…
What Is a Bundle Size Budget?A bundle size budget caps the byte size of compiled JavaScript or CSS bundles, failing the build when a chang…