93 lines
2.7 KiB
TypeScript
93 lines
2.7 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'
|
|
import { fileWatcher } from './plugin/file-watcher.ts'
|
|
import IconfontProcess from './plugin/iconfont-process.ts'
|
|
// import * as https from "node:https";
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig((configEnv) => {
|
|
const env = loadEnv(configEnv.mode, process.cwd(), "");
|
|
// const Agent = https.Agent;
|
|
// const agent = new Agent({
|
|
// keepAlive: true,
|
|
// // host: 'https://supervisory.njzscloud.com' // 显式指定请求的主机名为目标域名
|
|
// });
|
|
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),
|
|
fileWatcher(IconfontProcess),
|
|
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,
|
|
secure: false,
|
|
|
|
// agent,
|
|
|
|
changeOrigin: true,
|
|
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,
|
|
},
|
|
},
|
|
};
|
|
});
|