Files
Yi.Admin/Yi.Bbs.Vue3/vite.config.js

71 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-12-14 14:47:18 +08:00
import { fileURLToPath, URL } from "node:url";
2023-12-14 10:15:23 +08:00
2023-12-14 14:47:18 +08:00
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
2023-12-14 10:15:23 +08:00
2023-12-14 14:47:18 +08:00
var CopyWebpackPlugin = require("copy-webpack-plugin");
2023-12-14 10:15:23 +08:00
/** @type {import('vite').UserConfig} */
2023-12-14 14:47:18 +08:00
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
// envDir: 'env',
plugins: [
vue(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
}),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
2023-12-14 10:15:23 +08:00
},
2023-12-14 14:47:18 +08:00
},
server: {
2023-12-14 21:55:52 +08:00
port: 18001,
2023-12-14 14:47:18 +08:00
open: true,
proxy: {
[env.VITE_APP_BASEAPI]: {
target: env.VITE_APP_URL,
changeOrigin: true,
2024-01-04 22:31:19 +08:00
rewrite: (path) => path.replace(`${[env.VITE_APP_BASEAPI]}`, ""),
//查看真实代理url
// bypass(req, res, options) {
// const proxyUrl = options.target + options.rewrite(req.url);
// console.log(proxyUrl);
// req.headers['X-req-proxyURL'] = proxyUrl;
// res.setHeader('X-req-proxyURL', proxyUrl);
// }
2023-12-14 14:47:18 +08:00
},
2024-01-04 21:46:19 +08:00
[env.VITE_APP_BASE_WS]: {
target: env.VITE_APP_BASE_URL_WS,
changeOrigin: true,
2024-01-04 22:31:19 +08:00
rewrite: (p) => p.replace( `${[env.VITE_APP_BASE_WS]}`, ""),
2024-01-04 21:46:19 +08:00
ws: true,
2024-01-04 22:31:19 +08:00
//查看真实代理url
bypass(req, res, options) {
const proxyUrl = options.target + options.rewrite(req.url);
2024-07-21 13:37:56 +08:00
// console.log(proxyUrl);
2024-01-04 22:31:19 +08:00
req.headers['X-req-proxyURL'] = proxyUrl;
res.setHeader('X-req-proxyURL', proxyUrl);
}
2024-01-04 21:46:19 +08:00
},
2023-12-14 14:47:18 +08:00
},
},
// 增加新的配置
build: {
assetsInlineLimit: 0,
},
2023-12-14 14:47:18 +08:00
};
});