webpack打包优化
2021-05-07 20:26
标签:RoCE mes process Requires table plugin load type lis vue.config.js 安装包 添加gzip_static on; #静态压缩 安装 babel.config.js main.js 按需引入 webpack打包优化 标签:RoCE mes process Requires table plugin load type lis 原文地址:https://www.cnblogs.com/goddess/p/12088138.htmlvue-cli3 webpack优化
. 开启Gzip压缩
webpack配置
npm install compression-webpack-plugin -Dconst CompressionWebpackPlugin = require('compression-webpack-plugin')
module.exports = {
configureWebpack: config => {
// 开发环境不需要gzip
if (process.env.NODE_ENV !== 'production') return
config.plugins.push(
new CompressionWebpackPlugin({
// 正在匹配需要压缩的文件后缀
test: /\.(js|css|svg|woff|ttf|json|html)$/,
// 大于10kb的会压缩
threshold: 10240,
// 其余配置查看compression-webpack-plugin
})
)
}
}
服务端配置 开启gzip
location / {
root /med/dist;
index /index.html;
try_files $uri $uri/ /index.html;
gzip_static on; #静态压缩
}
}
.组件按需加载
elementUI
npm install babel-preset-env -D
npm install babel-plugin-component -D
plugins: [
[
'component',
{
'libraryName': 'element-ui',
'styleLibraryName': 'theme-chalk'
}
]
]
import Vue from 'vue';
import {
Dialog,
Input,
Button,
Table,
TableColumn,
Tooltip,
...
Loading,
Message,
} from 'element-ui';
Vue.use(Dialog);
Vue.use(Input);
Vue.use(Button);
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(Tooltip);
...
Vue.use(Loading.directive);
Vue.prototype.$loading = Loading.service;
Vue.prototype.$message = Message;
路由懒加载
{
name: 'collectioner_video_list',
path: 'ownerOrder',
// component: ownerOrder,
component: resolve => require(['@/pages/moniterCenter/ownerOrder'], resolve),
meta: {
requiresAuth: true
}
}
下一篇:JS MD5加密