You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.
原文链接:http://blog.meiqiu.me/2017/08/11/use-dllplugin-webpack/
为什么
在Vue-webpack-multi工程中,如果想抽出公共部分,可以使用CommonsChunk插件完成。它会把vue等公共部分打包为vendor,每个页面引入vendor.js。但依然会存在一些问题:
那么,如果有上述问题,可以引入DllPlugin抽出那些公用的,更新频度低的模块。思路类似与windows的dll文件。
怎么做
1、添加webpack.dll.config.js文件,这一步是为了告诉DllPlugin哪些文件需要抽出来,以及生成manifest.json配置文件。
2、在webpack.prod.config.js 文件中添加引用:DllReferencePlugin
3、在package.json文件中加入scripts:
4、运行:
会在static/js目录下生成vendor.dll.js。到此可以把文件加入html文件使用了。
5、更进一步
是的,以上配置并不会在html中自动插入vendor.dll.js。那么,我们还需要另一个插件AddAssetHtmlPlugin来完成这个任务。
首先引入依赖
在webpack.prod.config.js 文件中添加引用:AddAssetHtmlPlugin
这时,再次运行
html已自动引入vendor.dll.js。
参考:
The text was updated successfully, but these errors were encountered: