79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
import {
|
|
defineConfig,
|
|
loadEnv,
|
|
type ProxyOptions,
|
|
} from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
import VueDevTools from 'vite-plugin-vue-devtools'
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import processHtml from './plugin/html-process.ts'
|
|
import zipDist from './plugin/zip-dist.ts'
|
|
import path from 'node:path'
|
|
import ElementPlus from 'unplugin-element-plus/vite'
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig((configEnv) => {
|
|
const env = loadEnv(configEnv.mode, process.cwd(), '')
|
|
return {
|
|
base: env.VITE_APP_BASE_URL,
|
|
build: {
|
|
rollupOptions: {
|
|
treeshake: true,
|
|
},
|
|
},
|
|
css: {
|
|
modules: {
|
|
localsConvention: 'camelCase',
|
|
},
|
|
},
|
|
plugins: [
|
|
vue(),
|
|
vueJsx(),
|
|
VueDevTools(),
|
|
ElementPlus({
|
|
defaultLocale: 'zh-cn',
|
|
}),
|
|
AutoImport({
|
|
imports: [ 'vue', 'vue-router', 'pinia' ],
|
|
dts: './src/dts/auto-imports.d.ts',
|
|
resolvers: [ ElementPlusResolver() ],
|
|
}),
|
|
Components({
|
|
dts: './src/dts/components.d.ts',
|
|
dirs: [ './src/widgets' ],
|
|
resolvers: [ ElementPlusResolver() ],
|
|
}),
|
|
processHtml(env.VITE_APP_NAME),
|
|
zipDist(),
|
|
],
|
|
resolve: {
|
|
extensions: [ '.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json' ],
|
|
alias: [
|
|
{
|
|
find: '@',
|
|
replacement: path.resolve(__dirname, 'src'),
|
|
},
|
|
],
|
|
},
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 5173,
|
|
proxy: {
|
|
[env.VITE_HTTP_SERVER_BASE_URL]: {
|
|
proxyTimeout: 10000,
|
|
target: env.VITE_HTTP_PROXY_TARGET,
|
|
rewrite: path => env.VITE_HTTP_SERVER_BASE_URL == null || env.VITE_HTTP_SERVER_BASE_URL == '/' ? path : path.replace(new RegExp(env.VITE_HTTP_SERVER_BASE_URL), ''),
|
|
} as ProxyOptions,
|
|
[env.VITE_WS_SERVER_BASE_URL]: {
|
|
ws: true,
|
|
target: env.VITE_WS_PROXY_TARGET,
|
|
rewrite: (path) => (env.VITE_WS_SERVER_BASE_URL == null || env.VITE_WS_SERVER_BASE_URL == '/' ? path : path.replace(new RegExp(env.VITE_WS_SERVER_BASE_URL), '')),
|
|
} as ProxyOptions,
|
|
},
|
|
},
|
|
}
|
|
})
|