What is the benefit with migration from barrel imports to individual imports in angular material 9

Viewed 195
1 Answers

One main benefit - Performance

When you import like:

import perfrunner from 'perfrunner'

You importing the whole library into your code.

If you don't have tree shaking or it works not good enough - your application bundle might be significantly increased. This will lead to performance issues because bigger bundles load slower and parse slower. This is especially painful when you are using only 10% of the imported code and the library is big.

For this reason, lot's of libraries designed to support individual imports (like above) to allow you to use only things you really need.

Related