mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-06 23:25:06 +08:00
chore: 优化 vite 配置
This commit is contained in:
@ -1,19 +1,8 @@
|
||||
import { resolve } from 'path'
|
||||
import { loadEnv } from 'vite'
|
||||
import type { UserConfig, ConfigEnv } from 'vite'
|
||||
import Vue from '@vitejs/plugin-vue'
|
||||
import VueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import VueI18n from '@intlify/vite-plugin-vue-i18n'
|
||||
import WindiCSS from 'vite-plugin-windicss'
|
||||
import progress from 'vite-plugin-progress'
|
||||
import EslintPlugin from 'vite-plugin-eslint'
|
||||
import PurgeIcons from 'vite-plugin-purge-icons'
|
||||
import { createHtmlPlugin } from 'vite-plugin-html'
|
||||
import viteCompression from 'vite-plugin-compression'
|
||||
import vueSetupExtend from 'vite-plugin-vue-setup-extend'
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
||||
import { createStyleImportPlugin, ElementPlusResolve, VxeTableResolve } from 'vite-plugin-style-import'
|
||||
|
||||
import { createVitePlugins } from './build/vite'
|
||||
import { include, exclude } from "./build/vite/optimize"
|
||||
// 当前执行node命令时文件夹的地址(工作目录)
|
||||
const root = process.cwd()
|
||||
|
||||
@ -52,60 +41,8 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
Vue(),
|
||||
VueJsx(),
|
||||
WindiCSS(),
|
||||
progress(),
|
||||
PurgeIcons(),
|
||||
vueSetupExtend(),
|
||||
createStyleImportPlugin({
|
||||
resolves: [ElementPlusResolve(),VxeTableResolve()],
|
||||
libs: [{
|
||||
libraryName: 'element-plus',
|
||||
esModule: true,
|
||||
resolveStyle: (name) => {
|
||||
return `element-plus/es/components/${name.substring(3)}/style/css`
|
||||
}
|
||||
},{
|
||||
libraryName: 'vxe-table',
|
||||
esModule: true,
|
||||
resolveStyle: (name) => {
|
||||
return `vxe-table/es/${name}/style.css`
|
||||
}
|
||||
}]
|
||||
}),
|
||||
EslintPlugin({
|
||||
cache: false,
|
||||
include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx'] // 检查的文件
|
||||
}),
|
||||
VueI18n({
|
||||
runtimeOnly: true,
|
||||
compositionOnly: true,
|
||||
include: [resolve(__dirname, 'src/locales/**')]
|
||||
}),
|
||||
createSvgIconsPlugin({
|
||||
iconDirs: [pathResolve('src/assets/svgs')],
|
||||
symbolId: 'icon-[dir]-[name]',
|
||||
svgoOptions: true
|
||||
}),
|
||||
viteCompression({
|
||||
verbose: true, // 是否在控制台输出压缩结果
|
||||
disable: false, // 是否禁用
|
||||
threshold: 10240, // 体积大于 threshold 才会被压缩,单位 b
|
||||
algorithm: 'gzip', // 压缩算法,可选 [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
|
||||
ext: '.gz', // 生成的压缩包后缀
|
||||
deleteOriginFile: true //压缩后是否删除源文件
|
||||
}),
|
||||
createHtmlPlugin({
|
||||
inject: {
|
||||
data: {
|
||||
title: env.VITE_APP_TITLE,
|
||||
injectScript: `<script src="./inject.js"></script>`
|
||||
}
|
||||
}
|
||||
})
|
||||
],
|
||||
// 项目使用的vite插件。 单独提取到build/vite/plugin中管理
|
||||
plugins: createVitePlugins(env.VITE_APP_TITLE),
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
scss: {
|
||||
@ -139,37 +76,6 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
|
||||
}
|
||||
}
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: [
|
||||
'vue',
|
||||
'sass',
|
||||
'vue-router',
|
||||
'vue-types',
|
||||
'vue-i18n',
|
||||
'vxe-table',
|
||||
'vxe-table/es/style',
|
||||
'xe-utils',
|
||||
'lodash-es',
|
||||
'element-plus',
|
||||
'element-plus/es/locale/lang/zh-cn',
|
||||
'element-plus/es/locale/lang/en',
|
||||
'@iconify/iconify',
|
||||
'@vueuse/core',
|
||||
'qs',
|
||||
'axios',
|
||||
'pinia',
|
||||
'dayjs',
|
||||
'qrcode',
|
||||
'echarts/core',
|
||||
'echarts/charts',
|
||||
'echarts/components',
|
||||
'echarts/renderers',
|
||||
'echarts-wordcloud',
|
||||
'intro.js',
|
||||
'crypto-js',
|
||||
'@wangeditor/editor',
|
||||
'@wangeditor/editor-for-vue'
|
||||
]
|
||||
}
|
||||
optimizeDeps: { include, exclude }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user