写了个共用的chunk,没有办法实现代码分离。
搞了一个多小时,最后发现官方文档的这句话,吐血了!
webpack will automatically split chunks based on these conditions:
New chunk can be shared OR modules are from the node_modules folder
New chunk would be bigger than 30kb (before min+gz)
Maximum number of parallel requests when loading chunks on demand would be lower or equal to 5
Maximum number of parallel requests at initial page load would be lower or equal to 3
New chunk would be bigger than 30kb (before min+gz)!
New chunk would be bigger than 30kb (before min+gz)!
New chunk would be bigger than 30kb (before min+gz)!
重要的事说三遍。
在chunk里故意写了一些无效代码,扩充到30Kb以后,终于分离成功。
本文介绍了在使用webpack4的optimization.splitChunks进行代码分离时遇到的问题,重点强调了新生成的chunk大小需超过30kb(未压缩前)才能成功分离的细节,以及如何通过增加无效代码达到这一目标。
1万+

被折叠的 条评论
为什么被折叠?



