Imports and destructuring

When importing something using destructuring like:

import { myElement } from "lib/someLibrary";

The build system seems to be importing the whole “someLibrary” instead of only “myElement”.

Am I doing something wrong or is it the intended behavior?

Thanks!

This is the intended behaviour of ES Modules (though some tools to analyse and eliminate dead code do exist)

If the symbol you are looking for is exported by a single file deeper within the lib you can target it directly:

import { myElement } from "lib/someLibrary/elements/myElement";

This will only pull in the targeted file and it’s dependants

2 Likes

Great, thanks for the clarification!