Avoid duplicate code in bundle on dynamic import of webpack

550 Views Asked by At

I have two lerna packages. Both have lodash as peer dependency. And, on the main webpack, I am importing the package dynamically on click of separate buttons. Separate chunk file is created for each package. However, each chunk file contains lodash code as duplicated. How can I avoid this? Is there any way to check if all dependencies are loaded, then exclude to load again?

You can see the code in Github. This is a simplified version of what I am expecting.

I am looking for solution in Webpack3.

Thanks in advance.

PS: This is similar to SO question here. However, solution provided is not working for me. I tried with import as well as require.ensure. Both gave the same output bundle.

0

There are 0 best solutions below