Using npm modules

It depends how you import debounce – if you do so like

import { debounce } from 'lodash'

it will still include the entire lodash library in your bundle. If you only want to include the parts you need, you can do so like

import debounce from 'lodash/debounce'

and you’ll only get the minimally necessary parts. Another option is tree shaking, which will automatically detect and exclude the parts you don’t need.

PS: Keep in mind that when you’re including your dependencies in script tags, you don’t have such possibilities at all – you’re always pulling the entire library then. ;-)

2 Likes