解決vue?app.js/vender.js過(guò)大優(yōu)化啟動(dòng)頁(yè)
正文
只需要在運(yùn)行打包命令的后面加上"--report",完成以后就會(huì)跳轉(zhuǎn)到127.0.0.1:8888如上界面,然后根據(jù)界面分析修改。
npm run build --report
1、路由懶加載
import Home from '@/components/Home'
修改為
const Home = () => import('@/components/Home')2、開(kāi)啟gzip功能
打開(kāi)/config/index.js文件
productionGzip: true,
安裝
npm install --save-dev compression-webpack-plugin
如果報(bào)錯(cuò)
npm install --save-dev compression-webpack-plugin@1.1.11
后臺(tái)也需要配置,我們后臺(tái)是nginx
nginx.conf配置文件中修改
http {
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 8;
gzip_buffers 16 8k;
gzip_min_length 100;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript;
}重啟
systemctl reload nginx.service systemctl restart nginx.service
3、插件模塊組件按需加載
element-ui,iView等模塊用的哪個(gè)模塊的時(shí)候?qū)?/p>
這里遇到vue-echarts插件問(wèn)題,沒(méi)有做路由模塊懶加載的時(shí)候,只需要如下
import Echarts from 'vue-echarts'
Vue.components('chart', Echarts)但是做了模塊懶加載以后,就會(huì)報(bào)錯(cuò),說(shuō)是沒(méi)有引入統(tǒng)計(jì)圖的模塊
作如下改動(dòng)
import 'echarts/lib/chart/bar'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/pie'
import 'echarts/map/js/china'
...
const ECharts = () => import('vue-echarts')
Vue.component('chart', ECharts)4、使用CDN或者static靜態(tài)導(dǎo)入
這里使用www.jsdelivr.com CDN網(wǎng)站,速度快 具體說(shuō)明
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" rel="external nofollow" >
<link rel="stylesheet" rel="external nofollow" >
<link rel="stylesheet" rel="external nofollow" >
<link rel="stylesheet" rel="external nofollow" >
<link rel="stylesheet" rel="external nofollow" >
<link rel="stylesheet" rel="external nofollow" >
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-router@3.1.1/dist/vue-router.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios@0.19.2/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/element-ui@2.13.2/lib/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/iview@3.5.4/dist/iview.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/quill@1.3.7/dist/quill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-quill-editor@3.0.6/dist/vue-quill-editor.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.19/lodash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.27.0/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.27.0/locale/zh-cn.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-socket.io@3.0.7/dist/vue-socketio.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@4.1.0/dist/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts@4.1.0/map/js/china.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts-wordcloud@1.1.3/dist/echarts-wordcloud.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-echarts@4.0.2"></script>
<title>幫瀛</title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

以上就是解決vue app.js/vender.js過(guò)大優(yōu)化啟動(dòng)頁(yè)的詳細(xì)內(nèi)容,更多關(guān)于vue app.js/vender.js的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
VUE?axios每次請(qǐng)求添加時(shí)間戳問(wèn)題
這篇文章主要介紹了VUE?axios每次請(qǐng)求添加時(shí)間戳問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-01-01
vue/cli3.0腳手架部署到nginx時(shí)頁(yè)面空白的問(wèn)題及解決
這篇文章主要介紹了vue/cli3.0腳手架部署到nginx時(shí)頁(yè)面空白的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
VueCLI通過(guò)process.env配置環(huán)境變量的實(shí)現(xiàn)
本文主要介紹了VueCLI通過(guò)process.env配置環(huán)境變量的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
詳解Vue 普通對(duì)象數(shù)據(jù)更新與 file 對(duì)象數(shù)據(jù)更新
本篇文章主要介紹了詳解Vue 普通對(duì)象數(shù)據(jù)更新與 file 對(duì)象數(shù)據(jù)更新 ,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-04-04
Vite+Vue3.0+ElementPlus+axios+TS搭建項(xiàng)目全過(guò)程
文章主要介紹了如何使用Vite構(gòu)建項(xiàng)目,包括創(chuàng)建項(xiàng)目、代碼規(guī)范(eslint、husky、prettti等等、EditorConfig配置等),項(xiàng)目配置(CSS預(yù)處理器、樣式重置、環(huán)境變量配置、axios封裝、本地存儲(chǔ)封裝)和開(kāi)發(fā)生產(chǎn)環(huán)境配置等內(nèi)容2026-04-04
Vue2?Observer實(shí)例dep和閉包中dep區(qū)別詳解
這篇文章主要為大家介紹了Vue2?Observer實(shí)例dep和閉包中dep區(qū)別詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Vue3結(jié)合vue-cropper實(shí)現(xiàn)圖片裁剪預(yù)覽功能
??Vue-Cropper?? 是一個(gè)基于 Vue.js 的圖片裁剪組件庫(kù),專為 Web 應(yīng)用設(shè)計(jì),這篇文章主要為大家介紹了如何使用vue-cropper實(shí)現(xiàn)圖片裁剪預(yù)覽功能,需要的可以了解下2025-05-05

