I need an insight on how the bundle size of a web and mobile app would affect in the below scenario.
Scenario
There are 2 components Foo
and Bar
which import few libraries. Further, Foo
imports Bar
.
Foo.js
import { Text, Image, Card } from 'design-lib';
import { utilA, utilB } from 'util-lib-1';
import { utilC, utilD } from 'util-lib-2';
import { Bar } from './Bar';
const Foo = () => (
// JSX
<Bar />
// JSX
)
Bar.js
import { Text, Image, Card } from 'design-lib';
import { utilA, utilB } from 'util-lib-1';
import { utilC, utilD } from 'util-lib-2';
export const Bar = () => (
// JSX
)
Concern
These 6 import statements look like redundant code to me. So, following questions arise:
- Are these import statements really considered as a redundant code?
- Or is it that the compiled code won't have duplicate imports and combine code into single file with all import statements &
foo
bar
components at one place? - Would they increase the bundle size of a web and mobile app? If yes, what would be a better way to make code modular. I don't want to keep both the components in a single file.
Note: I know that the size of a lib won't double up in the final bundle if I import it twice. My concern is that each import statement must be having a size of few bytes. So, as these statements have been written twice in different files, would the compiled app have 2x the bytes each statement takes?