1. 路由懒加载
{
path: '/about',
name: 'about',
component: () => import('@/views/about/about'),
},
2. 不生成.map 文件
3. Element组件按需加载
npm install babel-plugin-component -D
module.exports = {
presets: [
[
'@vue/app',
{
useBuiltIns: "entry"
}
]
],
plugins: [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
4. echart优化
npm install babel-plugin-equire -D
module.exports = {
plugins: [
'equire'
],
}
const echarts = equire([
'title',
'legend',
'grid',
'line',
'bar',
'pie',
])
export default echarts
- 或者
import echarts from 'echarts/lib/echarts'
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/lines'
import 'echarts/lib/chart/radar'
import 'echarts/lib/component/legend'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/grid'
export default echarts
import echarts from '../echarts';
5. 图片的压缩合并
6. 添加分析工具
npm i webpack-bundle-analyzer
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