2024-08-22 11:27:06 +08:00
|
|
|
|
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from 'vite'
|
2024-08-08 19:08:15 +08:00
|
|
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
2024-08-07 21:48:57 +08:00
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
|
import path from 'path'
|
2024-08-22 11:27:06 +08:00
|
|
|
|
import { wrapperEnv } from './build/getEnv'
|
|
|
|
|
|
import { createProxy } from './build/proxy'
|
2024-08-07 21:48:57 +08:00
|
|
|
|
|
2024-08-21 14:52:36 +08:00
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
|
|
|
|
import Components from 'unplugin-vue-components/vite'
|
|
|
|
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
2024-08-08 19:08:15 +08:00
|
|
|
|
|
2024-08-22 11:27:06 +08:00
|
|
|
|
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
|
|
|
|
|
const root = process.cwd()
|
|
|
|
|
|
const env = loadEnv(mode, root)
|
|
|
|
|
|
const viteEnv = wrapperEnv(env)
|
|
|
|
|
|
return {
|
|
|
|
|
|
plugins: [
|
|
|
|
|
|
vue(),
|
|
|
|
|
|
// svg图标配置,可以使用svg图标
|
|
|
|
|
|
createSvgIconsPlugin({
|
|
|
|
|
|
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
|
|
|
|
|
|
symbolId: 'icon-[dir]-[name]',
|
|
|
|
|
|
}),
|
|
|
|
|
|
AutoImport({
|
|
|
|
|
|
resolvers: [ElementPlusResolver({
|
|
|
|
|
|
importStyle: 'sass',
|
|
|
|
|
|
})],
|
|
|
|
|
|
}),
|
|
|
|
|
|
Components({
|
|
|
|
|
|
resolvers: [ElementPlusResolver({
|
|
|
|
|
|
importStyle: 'sass',
|
|
|
|
|
|
})],
|
|
|
|
|
|
}),
|
|
|
|
|
|
],
|
|
|
|
|
|
// 基础配置
|
|
|
|
|
|
base: viteEnv.VITE_PUBLIC_PATH,
|
|
|
|
|
|
root,
|
|
|
|
|
|
publicDir: 'public',
|
|
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: {
|
|
|
|
|
|
'@': path.resolve(__dirname, 'src'),
|
|
|
|
|
|
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
css: {
|
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
|
scss: {
|
|
|
|
|
|
prependData: `@import "@/styles/var.scss";`,
|
2024-08-08 19:08:15 +08:00
|
|
|
|
},
|
2024-08-22 11:27:06 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
build: {
|
|
|
|
|
|
outDir: 'dist',
|
|
|
|
|
|
assetsDir: 'assets',
|
|
|
|
|
|
assetsInlineLimit: 4096,
|
|
|
|
|
|
cssCodeSplit: true,
|
|
|
|
|
|
sourcemap: false,
|
|
|
|
|
|
minify: 'terser',
|
|
|
|
|
|
terserOptions: {
|
|
|
|
|
|
compress: {
|
|
|
|
|
|
// 生产环境去除console及debug
|
|
|
|
|
|
drop_console: false,
|
|
|
|
|
|
drop_debugger: true,
|
2024-08-07 21:48:57 +08:00
|
|
|
|
},
|
2024-08-22 11:27:06 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
server: {
|
|
|
|
|
|
host: '0.0.0.0',
|
|
|
|
|
|
port: viteEnv.VITE_PORT,
|
|
|
|
|
|
open: viteEnv.VITE_OPEN,
|
|
|
|
|
|
cors: true,
|
|
|
|
|
|
proxy: createProxy(viteEnv.VITE_PROXY),
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
2024-08-07 21:48:57 +08:00
|
|
|
|
})
|