vite.config.js

javascript
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
//引入path用于写别名配置,自带无须安装
import path from 'path'
//使用svg-icons插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// eslint
import eslintPlugin from 'vite-plugin-eslint'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '') // 仅加载以 VITE_ 开头的环境变量
console.log('Current mode:', env)
return {
build: {
outDir: 'dist',
assetsDir: 'assets',
rollupOptions: {
output: {
entryFileNames: `assets/[name]-${env.VITE_APP_VERSION}-[hash].js`,
chunkFileNames: `assets/[name]-${env.VITE_APP_VERSION}-[hash][hash].js`,
assetFileNames: `assets/[name]-${env.VITE_APP_VERSION}-[hash][hash].[ext]`
}
}
},
plugins: [
vue(),
// 注册所有的svg文件生成svg雪碧图
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')], //svg图片存放的目录
symbolId: 'icon-[name]', // symbol的id
inject: 'body-last', // 插入的位置
customDomId: '__svg__icons__dom__' // svg的id
}),
// eslint引入
eslintPlugin({
include:['src/**/*.js','src/**/*.vue','src/*.vue','src/*.vue']
})
],
'process.env': {},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
}
})