This line of code is expensive to run:
require(`./path/to/large_file`)
Without it, the React app build bundle resulted in 36 MB.
With it, it resulted in 92 MB.
The above line of code is run during initiation.
I tried to lazy load it by instead return this:
function lazy_loader() {
return () => require(`./path/to/large_file`)
}
And during initiation, I the instead only runs:
lazy_loader();
lazy_loader() only returns a function, which will require the large_file if run.
However, this actually made no difference at all.
The build bundle size is still 92 MB.
Can someone explain why this didn't help?
And if possible what I can do to fix this?