Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why webpack includes elliptic bn.js modules in my bundle

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

npm ls bn.js gives:

├─┬ [email protected]
│ └─┬ [email protected]
│   └─┬ [email protected]
│     └─┬ [email protected]
│       └── [email protected]
like image 568
Nikhil Ranjan Avatar asked Feb 27 '17 17:02

Nikhil Ranjan


People also ask

Why do we need Webpacks?

Application of Webpack:It helps to use different javascript files without having tension that will load first. It makes code shorter. It helps in converting many files other than javascript into modules. It compiles different javascript module.

Do we need Webpack for Node JS?

Do you really need Webpack for a server side JavaScript project? As is usually the case in software engineering, the answer is “it depends.” If you're building a basic Express app that runs on Node. js, you don't need Webpack at all.

Why we use Webpack in react JS?

Your browser doesn't know how to import App from the ./App directory. The browser can only load static JS files. Hence, webpack configuration is needed for converting your React app into readable code that browsers can understand.

Do we still need Webpack?

Should I Use Webpack? If you're building a complex Front End™ application with many non-code static assets such as CSS, images, fonts, etc, then yes, Webpack will give you great benefits.


1 Answers

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

To avoid these huge dependencies, you can look for a specific npm module which provides just the function(ality) you need.

For example, I was importing crypto to do;

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

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

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

In case you need some motivation; removing crypto as a dependancy trimmed 150Kb off our gzipped bundle size (but YMMV depending on which crypto methods you're using).

like image 168
Matt Avatar answered Sep 24 '22 06:09

Matt