代码拉取完成,页面将自动刷新
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import legacy from '@vitejs/plugin-legacy'
import { createHtmlPlugin } from 'vite-plugin-html'
import { projectName } from './package.json'
import vueJsx from '@vitejs/plugin-vue-jsx'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// 为了在vite.config执行时能获取环境变量,使用loadEnv来获取
// 依旧沿用mode来做区分
const env = loadEnv(mode, process.cwd())
return {
base: env.VITE_STATIC_URL,
plugins: [
vue(),
vueJsx(),
// 参考element-plus文档,自动导入组件
AutoImport({
resolvers: [
ElementPlusResolver(),
IconsResolver({
prefix: 'Icon'
})
]
}),
Components({
resolvers: [
ElementPlusResolver(),
IconsResolver({
enabledCollections: ['ep']
})
]
}),
Icons({
autoInstall: true
}),
legacy({
additionalLegacyPolyfills: ['regenerator-runtime/runtime'] // 面向IE11
}),
createHtmlPlugin({
minify: true,
inject: {
data: {
title: projectName,
links: `<link href="/static/css/normalize.css" rel="stylesheet"/><link href="/static/css/main.css" rel="stylesheet"/>`
}
}
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
build: {
rollupOptions: {
output: {
// manualChunks: {
// echarts: ['echarts'],
// lodash: ['lodash']
// }
manualChunks: (id) => {
if (id.includes('node_modules')) {
if (id.endsWith('.css')) {
return 'vendor'
}
if (id.includes('echarts')) {
return 'echarts'
}
if (id.includes('lodash')) {
return 'lodash'
}
if (id.includes('element-plus')) {
return 'elementPlus'
}
}
}
}
},
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
}
}
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。