import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'
import EslintPlugin from 'vite-plugin-eslint'
import AutoImport from 'unplugin-auto-import/vite'
import DefineOptions from 'unplugin-vue-define-options/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import'
export default defineConfig({
plugins: [
vue(),
VueJsx(),
Components({
dirs: ['src/components'],
extensions: ['vue'],
deep: true,
dts: 'src/types/auto-components.d.ts',
include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/],
resolvers: [ElementPlusResolver()],
exclude: [/[\\/]node_modules[\\/]/]
}),
AutoImport({
dts: 'src/types/auto-imports.d.ts',
include: [/\.[tj]sx?$/, /\.vue$/],
imports: ['vue', 'vue-router'],
resolvers: [
ElementPlusResolver()
],
eslintrc: {
enabled: false,
filepath: './.eslintrc-auto-import.json',
globalsPropValue: true
}
}),
createStyleImportPlugin({
resolves: [ElementPlusResolve()],
libs: [{
libraryName: 'element-plus',
esModule: true,
resolveStyle: (name) => {
return `element-plus/es/components/${name.substring(3)}/style/css`
}
}]
}),
EslintPlugin({
cache: false,
include: ['src/**/*.vue', 'src/**/*.ts', 'src/**/*.tsx']
}),
DefineOptions()
],
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/assets/scss/index.scss";`
}
}
},
resolve: {
alias: {
'@': resolve(__dirname, './src')
}
},
build: {
minify: 'terser',
outDir: 'dist',
sourcemap: 'inline',
terserOptions: {
compress: {
drop_debugger: true,
drop_console: false
}
}
},
server: {
host: 'localhost',
port: 8080,
open: true,
headers: {
'Access-Control-Allow-Origin': '*'
},
proxy: {
'/api': {
target: 'http://',
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/api/, 'api')
}
},
hmr: true,
}
})