Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

项目包大小优化记录 bn.js ellptic.js #10

Open
qppq54s opened this issue Jun 19, 2020 · 0 comments
Open

项目包大小优化记录 bn.js ellptic.js #10

qppq54s opened this issue Jun 19, 2020 · 0 comments

Comments

@qppq54s
Copy link
Owner

qppq54s commented Jun 19, 2020

webpack打包完成后,发现index.js有将近600k(压缩后),其中,有bn.js和ellptic.js有将近400k大小,分析node_modules依赖后,发现,postcss-cssnext包里有这个依赖,是我们的postcss-loader在线上环境也开启了source-map: true导致的。
把source-map: true 移除后,发现这两个包还在。
一顿google后,发现如果在项目中引用了crypto,也对导致webpack打入这两个依赖
之后,在我们的请求库里,发现我们使用了crypto-js@4.0.0,而crypto-js的core.js文件中有这么一段代码
// Native crypto import via require (NodeJS) if (!crypto && typeof require === 'function') { try { crypto = require('crypto'); } catch (err) {} }
导致webpack打包的时候还是依赖了crypto。然而,之前的版本crypto-js@3.3.0并没有加入这段代码,所以暂时把crypto-js的版本锁定为3.3.0。

这两个改动之后,index.js包里终于没有bn.js和ellptic.js,包大小也减少了400k左右。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant