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

引入内核 '@cloudbase/js-sdk/app' 后,包大小增加了 675 KB #1

Closed
imaegoo opened this issue Aug 11, 2020 · 3 comments
Closed

Comments

@imaegoo
Copy link

imaegoo commented Aug 11, 2020

关于 js-sdk 迁移的这篇文档:https://docs.cloudbase.net/api-reference/webv2/initialization.html#shi-yong

我的一个项目,从 tcb-js-sdk 迁移之后,webpack 打包后的大小反而增加了。

// 1. 之前用的是 tcb-js-sdk@1.10.7,打包后大小是 478 KB (490,352 bytes)
import * as tcbSdk from 'tcb-js-sdk'

// 2. 按需引入 @cloudbase/js-sdk@1.0.2,打包后大小是 895 KB (916,594 bytes)
import cloudbase from '@cloudbase/js-sdk/app'
import '@cloudbase/js-sdk/auth'
import '@cloudbase/js-sdk/functions'

// 3. 全量引入 @cloudbase/js-sdk@1.0.2,打包后大小是 1.04 MB (1,095,589 bytes)
import cloudbase from '@cloudbase/js-sdk'

// 4. 只引内核,打包后大小是 852 KB (872,740 bytes)
import cloudbase from '@cloudbase/js-sdk/app'

// 5. 什么都不引,打包后大小是 177 KB (182,089 bytes)

https://imgcache.qq.com/qcloud/cloudbase-js-sdk/1.0.2/cloudbase.full.js 这个全量 js 明明也只有 297 KB。

看起来是 '@cloudbase/js-sdk/app' 这个东西一引就非常大,请问是什么原因?

PS: 我确定不是我忘记删除 tcb-js-sdk 引用的原因,我已经 yarn remove 了,而且整个项目都搜索不到 tcb-js-sdk 了。

@zhoujunpeng
Copy link
Contributor

zhoujunpeng commented Aug 11, 2020

@imaegoo @cloudbase/js-sdk用到了crypto-js,这个模块存在一个bug导致webpack会把原生crypto模块打包进来,参考brix/crypto-js#276
如果你比较着急上线的话可以通过配置webpack的externals暂时规避,如下:

externals: { crypto: 'crypto'}

我们会尽快研究可替代方案,尽快解决。

@zhoujunpeng
Copy link
Contributor

@imaegoo 1.0.3版本已解决此问题

@imaegoo
Copy link
Author

imaegoo commented Aug 12, 2020

@zhoujunpeng 回复真及时,问题已解决,感谢。

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

2 participants