1

Webpack 4+ already comes with optimisation out of the box.

There is still one unclear thing to me:

Does deduplication happen across dependencies?

example:

/node_modules/foo has a bundled dependency 'foobar'

but also

/node_modules/bar has a bundled dependency 'foobar'

does webpack dedupe the foobar dependency when I import both into my main bundle?

import foo from 'foo';
import baz from 'baz';

foo(baz('hello world'));

I would say it doesn't, since those packages come already bundled, but I couldn't find any official documentation about it...

Hitmands
  • 13,491
  • 4
  • 34
  • 69

1 Answers1

0

It depends, if the imports from foo & bar are imports to a module foobar, then this module become a part of the deps tree of you app, therefore it will be only once at the tree.

If foo & bar has a copy of the code, webpack will not able to "identify" that code as duplicated and won't be able to keep only one copy.

felixmosh
  • 32,615
  • 9
  • 69
  • 88