HTML中直接引入项目中的依赖包(压缩包)
<!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("您的浏览器版本过低,有安全隐患,请下载最新版的浏览器");
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自动就挂载在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: {
// 去掉注释内容
comments: true
}
},
sourceMap: false,
parallel: true
})
];
// 只有打包生产环境才需要将console删除
if (process.env.VUE_APP_build_type == "production") {
config.plugins = [...config.plugins, ...plugins];
}
},
这样去掉console,再把一些大点的包提出去不打包它,会发现chunk-vendors...js明显小了很多
然后nginx开启gzip
https://www.cnblogs.com/xzkzzz/p/9224358.html
https://zhuanlan.zhihu.com/p/24764131
https://www.jianshu.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 后面设置映射的路径
location /api {
proxy_pass https://test.ali.com;
}
}