加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vite.config.ts 3.20 KB
一键复制 编辑 原始数据 按行查看 历史
space_long 提交于 2024-05-22 10:23 . init
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'
// 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(),
// 参考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
}
}
}
}
})
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化