一。引入 CDN
// 不會發(fā)生變動(dòng)的js庫可以放入script標(biāo)簽中,從外部引入
// 注意一點(diǎn):格式為 'aaa' : 'bbb', 其中,aaa表示要引入的資源的名字,bbb表示該模塊提供給外部引用的名字,由對應(yīng)的庫自定。例如,vue為Vue,vue-router為VueRouter.
webpack.base.conf.js文件
externals: {
'vue':'Vue',
'html2canvas': 'html2canvas',
'vue-router': 'VueRouter',
'vuex': 'Vuex',
'crypto-js': 'CryptoJS',
'jsencrypt': 'JSEncrypt'
},
index.html文件
<script src="https://cdn.staticfile.org/html2canvas/0.5.0-beta4/html2canvas.min.js"></script>
<script src="https://cdn.staticfile.org/vue-router/3.0.1/vue-router.min.js"></script>
<script src="https://cdn.staticfile.org/vuex/3.0.1/vuex.min.js"></script>
<script src="https://cdn.staticfile.org/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="https://cdn.staticfile.org/jsencrypt/3.0.0-rc.1/jsencrypt.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.10/vue.min.js"></script>
二。去除 .map文件
在項(xiàng)目 根目錄 config/index.js 中 build 內(nèi)找到 productionSourceMap: true, 把 true改為****false。從而重新打包以后,系統(tǒng)就不會自動(dòng)生成 map文件了。

image
三。使用Gzip壓縮
1.服務(wù)器那邊得開啟gzip

image.png
2.根目錄config/index.js 中 build 內(nèi)找到 **productionGzip: false, **把 **false****改為****true。

image
3.安裝插件 compression-webpack-plugin 注:安裝的時(shí)候帶上版本號,現(xiàn)在 compression-webpack-plugin 2.0已出,默認(rèn)該命令安裝最新版,最新版本和當(dāng)前的webpack不匹配,要報(bào)錯(cuò)。
cnpm install --save-dev compression-webpack-plugin@1.1.12