vueComponent / ant-design-vue

🌈 An enterprise-class UI components based on Ant Design and Vue. 🐜
https://antdv.com/
Other
19.86k stars 3.73k forks source link

动态导入组件,打包时,包变的超级大 #2727

Closed xuejiaomeng closed 3 years ago

xuejiaomeng commented 3 years ago

Version

1.6.4

Environment

vue 2.5.17 ,Chrome浏览器, mac

Reproduction link

https://webpack.js.org/api/module-methods/#import

Steps to reproduce

在添加路由前处理, const componentPath ='/views/dashboard/Workplace' data['component'] =()=>import(@${componentPath}) 组件动态导入成功了,但是打包的时候由原来的3M变成了44M image

What is expected?

打包后还是3M,在路由上能动态加载组件

What is actually happening?

组件动态导入成功了,但是打包的时候由原来的3M变成了44M

sendya commented 3 years ago

这跟组件库没什么关系,是 webpack 对 import 的处理原理导致的, 如果你有了解动态导入的实现原理。应当主动避免直接完全动态路径,而至少指定到特定层级。比如 @/views/${componentPath} 这样 webpack 就只会把 @/views 目录下的所有文件进行动态打包加载

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.