brix / crypto-js

JavaScript library of crypto standards.
Other
15.86k stars 2.39k forks source link

Huge bundle size difference after latest update #321

Open MalekBouba opened 4 years ago

MalekBouba commented 4 years ago

I noticed a big bundle size change after updating from 3.3.0 to 4.0.0

Screen Shot 2020-10-10 at 1 17 23 AM

I didn't touch anything else in my code. +112.79 KB gzipped added without any change besides the update in package.json!

Maybe this is shadowed by #320 so, no one sees the difference, or it's just happening to me alone?

Should I just revert to the previous version? Any idea? Thanks...

nagiek commented 4 years ago

Have same problem with 4.0.0 even with modular import

i.e. import AES from 'crypto-js/aes';

perqa commented 4 years ago

@MalekBouba, @nagiek See this: https://github.com/brix/crypto-js/issues/168#issuecomment-714381843

coolhome commented 3 years ago

Looking into the IdentityModel/oidc-client-js#1292 issue I identified these lines as the cause for the increase build sizes. Removing these reduce the build from 800KB -> 397KB uncompressed and 171 KB compressed like the version before. Not really sure the proper way to handle this with NPM packages.

https://github.com/brix/crypto-js/blob/4.0.0/core.js#L40-L45

Before: image

After: image

Hinaser commented 3 years ago

For future readers, I suggest using jscrypto as a crypto-js enhancement. Because I also was troubled by huge bundle size with crypto-js, I decided to develop enhancement for crypto-js.

jscrypto supports es6/typescript/cjs/browser environment with reduced bundle size.

You can utilize es6 bundler's TreeShaking mechanism to greatly reduce bundle size.

// This only import least dependencies when you make bundle.
import {SHA256} from "jscrypto/es6/SHA256";

Or, if you need to use crypto-js and desparately in need to reduce bundle size, another option is use webpack5. Unlike webpack <= 4, webpack 5 can greatly reduce bundle size even crypto-js itself not changing at all.

cadenzah commented 2 years ago

It seems fixed currently with v4.1.1, right? When I upgraded crypto-js from v4.0.0 to v4.1.1, I experienced huge reduce of bundle size when looking at it with webpack bundle analyzer. I hope any author confirms this as this change is not mentioned anywhere.