-
Notifications
You must be signed in to change notification settings - Fork 292
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
第 9 题: 简单实现项目代码按需加载,例如import { Button } from 'antd',打包的时候只打包button #9
Comments
請問何時會需要如此功能呢?(搔頭 |
看来你还不知道按需使用antd,或者其他第三方的库,这是减少包体积的常见问题呀 |
喔 現在看懂了,原本以為是要延伸或是縮小第三方庫單一組件代碼。 |
嗯 现在webpack的tree shaking 和antd自带的一个plugin也有按需加载 这题就考一下按需加载的实现原理 当然 我的答案是通过编写babel插件去实现按需加载 你要是有别的方法 也可以共享出来 |
webpack4 + babel7 已经可以实现tree shaking了 |
太苦了吧 |
原理很简单,就是将
通过babel转化成
自定义拓展一个babel插件,代码如下:
The text was updated successfully, but these errors were encountered: