HTML中直接引入項(xiàng)目中的依賴包(壓縮包)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript">
// IE11以下
if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE6.0" || navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE7.0" || navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE8.0" || navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE9.0" || navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.split(";")[1].replace(/[ ]/g, "") == "MSIE10.0") {
alert("您的瀏覽器版本過(guò)低,有安全隱患,請(qǐng)下載最新版的瀏覽器");
window.open("http://www.firefox.com.cn/", "_self");
}
</script>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="imagetoolbar" content="false">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache" content="no-cache">
<link id="linkIco" rel="icon" href="<%= BASE_URL %>favicon.ico">
<script src="<%= BASE_URL %>vue.min.js"></script>
<script src="<%= BASE_URL %>vue-router.min.js"></script>
<script src="<%= BASE_URL %>vuex.min.js"></script>
<script src="<%= BASE_URL %>element-ui.js"></script>
<script src="<%= BASE_URL %>jelement.min.js"></script>
<title> </title>
<style>[v-cloak] {display: none;}</style>
</head>
<body>
<noscript>
<strong>We're sorry but pingyiweb doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
vue.config.js中
configureWebpack: config => {
// 入口文件
config.entry.app = ["babel-polyfill", "./src/main.js"];
// element-ui自動(dòng)就掛載在Vue上了,這里不需要寫它氓栈,在入口文件main.js中也不用再vue.use了
config.externals = {
'vue': 'Vue',
'vuex': 'vuex',
'vue-router': 'VueRouter'
};
// 刪除console插件
let plugins = [
new UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: false,
drop_console: true,
drop_debugger: true
},
output: {
// 去掉注釋內(nèi)容
comments: true
}
},
sourceMap: false,
parallel: true
})
];
// 只有打包生產(chǎn)環(huán)境才需要將console刪除
if (process.env.VUE_APP_build_type == "production") {
config.plugins = [...config.plugins, ...plugins];
}
},
這樣去掉console,再把一些大點(diǎn)的包提出去不打包它,會(huì)發(fā)現(xiàn)chunk-vendors...js明顯小了很多
然后nginx開(kāi)啟gzip
https://www.cnblogs.com/xzkzzz/p/9224358.html
https://zhuanlan.zhihu.com/p/24764131
http://www.reibang.com/p/06b44ba366ab
server {
listen 9999;
server_name localhost;
gzip on;
gzip_min_length 100;
gzip_types text/plain text/css application/xml application/javascript;
gzip_vary on;
location / {
root D:/0-workspace/haha-console;
index index.html index.htm;
try_files $uri $uri/ /hahaConsole/index.html;
#add_header Access-Control-Allow-Origin *;
}
#反向代理的路徑(和upstream綁定)创夜,location 后面設(shè)置映射的路徑
location /api {
proxy_pass https://test.ali.com;
}
}