优化:提升性能
This commit is contained in:
@@ -6,6 +6,8 @@ import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
|
||||
import { EleAdminResolver } from 'ele-admin-pro/lib/utils/resolvers';
|
||||
import { DynamicAntdLess } from 'ele-admin-pro/lib/utils/dynamic-theme';
|
||||
import { resolve } from 'path';
|
||||
import { visualizer } from 'rollup-plugin-visualizer';
|
||||
import { splitVendorChunkPlugin } from 'vite';
|
||||
|
||||
export default defineConfig(({ command }) => {
|
||||
const isBuild = command === 'build';
|
||||
@@ -24,7 +26,12 @@ export default defineConfig(({ command }) => {
|
||||
// }
|
||||
// },
|
||||
plugins: [
|
||||
vue(),
|
||||
vue({
|
||||
script: {
|
||||
defineModel: true,
|
||||
propsDestructure: true
|
||||
}
|
||||
}),
|
||||
// 组件按需引入
|
||||
ViteComponents({
|
||||
dts: false,
|
||||
@@ -38,14 +45,30 @@ export default defineConfig(({ command }) => {
|
||||
],
|
||||
directoryAsNamespace: true
|
||||
}),
|
||||
// 代码分割
|
||||
splitVendorChunkPlugin(),
|
||||
// gzip 压缩
|
||||
ViteCompression({
|
||||
disable: !isBuild,
|
||||
threshold: 10240,
|
||||
algorithm: 'gzip',
|
||||
ext: '.gz'
|
||||
}),
|
||||
// brotli 压缩
|
||||
ViteCompression({
|
||||
disable: !isBuild,
|
||||
threshold: 10240,
|
||||
algorithm: 'brotliCompress',
|
||||
ext: '.br'
|
||||
}),
|
||||
// 打包分析
|
||||
isBuild && visualizer({
|
||||
filename: 'dist/stats.html',
|
||||
open: false,
|
||||
gzipSize: true,
|
||||
brotliSize: true
|
||||
})
|
||||
],
|
||||
].filter(Boolean),
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
less: {
|
||||
@@ -68,12 +91,69 @@ export default defineConfig(({ command }) => {
|
||||
'echarts/components',
|
||||
'vue-echarts',
|
||||
'echarts-wordcloud',
|
||||
'xlsx'
|
||||
]
|
||||
'xlsx',
|
||||
'lodash-es',
|
||||
'dayjs',
|
||||
'crypto-js',
|
||||
'js-md5',
|
||||
'qrcode',
|
||||
'nprogress'
|
||||
],
|
||||
exclude: ['@iconify/json']
|
||||
},
|
||||
build: {
|
||||
target: 'chrome63',
|
||||
chunkSizeWarningLimit: 2000
|
||||
target: 'es2015',
|
||||
cssCodeSplit: true,
|
||||
chunkSizeWarningLimit: 1000,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
// 手动分包
|
||||
manualChunks: {
|
||||
// Vue 生态
|
||||
'vue-vendor': ['vue', 'vue-router', 'pinia'],
|
||||
// UI 组件库
|
||||
'ui-vendor': ['ant-design-vue', 'ele-admin-pro'],
|
||||
// 工具库
|
||||
'utils-vendor': ['lodash-es', 'dayjs', 'crypto-js', 'js-md5'],
|
||||
// 图表库
|
||||
'charts-vendor': ['echarts', 'vue-echarts', 'echarts-wordcloud'],
|
||||
// 编辑器
|
||||
'editor-vendor': ['tinymce', 'bytemd', 'md-editor-v3'],
|
||||
// 文件处理
|
||||
'file-vendor': ['xlsx', 'exceljs', 'file-saver', 'ali-oss']
|
||||
},
|
||||
// 文件命名
|
||||
chunkFileNames: (chunkInfo) => {
|
||||
const facadeModuleId = chunkInfo.facadeModuleId
|
||||
? chunkInfo.facadeModuleId.split('/').pop().replace(/\.\w+$/, '')
|
||||
: 'chunk';
|
||||
return `js/${facadeModuleId}-[hash].js`;
|
||||
},
|
||||
assetFileNames: (assetInfo) => {
|
||||
const info = assetInfo.name.split('.');
|
||||
const ext = info[info.length - 1];
|
||||
if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(assetInfo.name)) {
|
||||
return `media/[name]-[hash].${ext}`;
|
||||
}
|
||||
if (/\.(png|jpe?g|gif|svg)(\?.*)?$/.test(assetInfo.name)) {
|
||||
return `images/[name]-[hash].${ext}`;
|
||||
}
|
||||
if (/\.(woff2?|eot|ttf|otf)(\?.*)?$/i.test(assetInfo.name)) {
|
||||
return `fonts/[name]-[hash].${ext}`;
|
||||
}
|
||||
return `assets/[name]-[hash].${ext}`;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 压缩配置
|
||||
minify: 'terser',
|
||||
terserOptions: {
|
||||
compress: {
|
||||
drop_console: true,
|
||||
drop_debugger: true,
|
||||
pure_funcs: ['console.log']
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user