Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The same dependency is included many times in my bundle

Tags:

webpack

In my bundle, the same node_modules/bn.js/lib dependency is included 8 times in my production bundle.

enter image description here

Any idea why and how to prevent it?

like image 684
Grant Avatar asked Dec 03 '20 01:12

Grant


1 Answers

In this case, I was able to add a resolve.alias to my config.

const p = require('path')

module.exports = {
  resolve: {
    alias: {
      'bn.js': p.join(__dirname, 'node_modules/bn.js/lib/bn.js'),
    }
  },
  // ...
}

Not sure if that's the right way, but it's no longer duplicated in my bundle.

like image 144
Grant Avatar answered Nov 27 '22 14:11

Grant