Does webpack 4 dedupe npm packages that have, in turn, already been bundled by webpack?

Viewed 1487

I have seen other similar questions. The questions I have seen were asked before the release of Webpack 4, did not ask specifically about npm, and were not definitively answered.

Let's say I use webpack to bundle a package that includes dependencies, and I don't want to categorize these dependencies as webpack externals and npm peer dependencies. I then publish this package to npm.

Someone downloads my package and uses it as part of a project. That project already includes one of my package's dependencies. Let's say this project is, in turn, bundled by webpack.

1.) Will webpack recognize and dedupe the duplicate dependencies when the project is bundled?

2.) If not, and if I don't use webpack to bundle my npm package, would it allow webpack to dedupe the duplicate dependencies when the project is bundled?

3.) What are best practices along these lines?

1 Answers

if you are already distributing a file that is bundled by webpack with all the dependencies, you don't need to declare dependencies nor peerDependencies.

1.) Will webpack recognize and dedupe the duplicate dependencies when the project is bundled?

Yes

3.) What are best practices along these lines?

Publish bundle with externals and peer dependencies and let the bundle happen on the user side.

Related