Why does the web package include elliptical bn.js modules in my package

webpack-bundle-analyzer shows the elliptical and bn.js included in my vendor.js But these modules are not used in the code or are included in package.json.

npm ls bn.js gives:

├─┬ eslint-import-resolver-webpack@0.8.1 │ └─┬ node-libs-browser@1.1.1 │ └─┬ crypto-browserify@3.11.0 │ └─┬ browserify-sign@4.0.0 │ └── bn.js@4.11.6 
+6
source share
2 answers

Webpack includes elliptic and bn.js (and other, smaller modules) in your package if you import crypto as a dependency somewhere in your code.

To avoid these huge dependencies, you can find the specific npm module that provides only the (ality) function that you need.

For example, I imported crypto to execute;

 const crypto = require('crypto'); const hmac = crypto.createHmac('sha1', buf); 

... instead (in this situation ...) you can install create-hmac module and do;

 const createHmac = require('create-hmac'); const hmac = createHmac('sha1', buf); 

If you need motivation; removing crypto as dependencies, trimmed to 150 KB from our gzipped bundle size (but YMMV depending on which crypto methods you use).

+1
source

These are the dependencies of your dependencies. For example, the source

-2
source

Source: https://habr.com/ru/post/1015316/


All Articles