'Removing dependency from Next.js dynamic bundle

When using a Next.js dynamic import. Next.js will bundle the imported module and serve that file.

Let's say that file uses a dependency like styled-components, this is already apart of the main app and has been loaded. I'd like a way to omit dependencies from within the dynamically generated bundle.



Solution 1:[1]

I think that this only happens when running in Dev mode, if you build for production the bundles are optimized.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ThomasReggi