一,查看包占用
1,安装插件
cnpm intall webpack-bundle-analyzer -D
然后新建vue.config.js,对 webpack进行配置:
module.exports = {
chainWebpack: (config) => {
/* 添加分析工具*/
if (process.env.NODE_ENV === 'production') {
if (process.env.npm_config_report) {
config
.plugin('webpack-bundle-analyzer')
.use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
.end();
config.plugins.delete('prefetch')
}
}
}
}
再运行 npm run build --report
会在浏览器打开一个项目打包的情况图,便于直观地比较各个 bundle文件的大小
发现echarts比较大,现在注释掉echarts,重新运行 npm run build --report
二,ui框架按需加载
import { Button, Input, Pagination, Table, TableColumn, MessageBox } from 'element-ui';
Vue.use(Button)
Vue.use(Input)
Vue.use(Pagination)
Vue.prototype.$alert = MessageBox.alert