|
@@ -1,33 +1,41 @@
|
|
|
import { defineConfig, loadEnv } from "vite";
|
|
|
import vue from "@vitejs/plugin-vue";
|
|
|
import path from "node:path";
|
|
|
-import { createHtmlPlugin } from 'vite-plugin-html';
|
|
|
-import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
|
|
-import { version } from './package.json'
|
|
|
+import { createHtmlPlugin } from "vite-plugin-html";
|
|
|
+import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
|
|
|
+import { version } from "./package.json";
|
|
|
|
|
|
// https://vite.dev/config/
|
|
|
export default ({ mode }: any) => {
|
|
|
- const env = loadEnv(mode, process.cwd())
|
|
|
+ const env = loadEnv(mode, process.cwd());
|
|
|
|
|
|
- let proxy: any = {}
|
|
|
+ let proxy: any = {};
|
|
|
if (env.VITE_MOCK_ENV) {
|
|
|
- const mockEnv = loadEnv(env.VITE_MOCK_ENV, process.cwd())
|
|
|
+ const mockEnv = loadEnv(env.VITE_MOCK_ENV, process.cwd());
|
|
|
+
|
|
|
const getProxy = (prev: string, api: string) => ({
|
|
|
target: api,
|
|
|
changeOrigin: true,
|
|
|
- rewrite: (path: any) => path.replace(prev, '')
|
|
|
- })
|
|
|
+ rewrite: (path: any) => path.replace(prev, ""),
|
|
|
+ });
|
|
|
|
|
|
- for (const key in env) {
|
|
|
- if (env[key].includes('/') && env[key] !== mockEnv[key]) {
|
|
|
- proxy[env[key]]= getProxy(env[key], mockEnv[key])
|
|
|
+ if (env.VITE_MOCK_PROXY) {
|
|
|
+ proxy[env.VITE_MOCK_PROXY] = getProxy(
|
|
|
+ env.VITE_MOCK_PROXY,
|
|
|
+ mockEnv.VITE_MOCK_PROXY
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ for (const key in env) {
|
|
|
+ if (env[key].includes("/") && env[key] !== mockEnv[key]) {
|
|
|
+ proxy[env[key]] = getProxy(env[key], mockEnv[key]);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- console.log(proxy)
|
|
|
+ console.log(proxy);
|
|
|
|
|
|
return defineConfig({
|
|
|
- base: './',
|
|
|
+ base: "./",
|
|
|
resolve: {
|
|
|
alias: {
|
|
|
"@/": `${path.resolve(__dirname, "src")}/`,
|
|
@@ -57,22 +65,22 @@ export default ({ mode }: any) => {
|
|
|
},
|
|
|
plugins: [
|
|
|
createSvgIconsPlugin({
|
|
|
- iconDirs: [path.resolve(process.cwd(), 'public/icons')],
|
|
|
- symbolId: 'icon-[dir]-[name]'
|
|
|
+ iconDirs: [path.resolve(process.cwd(), "public/icons")],
|
|
|
+ symbolId: "icon-[dir]-[name]",
|
|
|
}),
|
|
|
- createHtmlPlugin({
|
|
|
- template: 'index.html',
|
|
|
- entry: path.resolve('src', env.VITE_ENTRY),
|
|
|
+ createHtmlPlugin({
|
|
|
+ template: "index.html",
|
|
|
+ entry: path.resolve("src", env.VITE_ENTRY),
|
|
|
inject: {
|
|
|
data: {
|
|
|
title: env.VITE_TITLE,
|
|
|
},
|
|
|
- }
|
|
|
- }),
|
|
|
- vue()
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ vue(),
|
|
|
],
|
|
|
define: {
|
|
|
- __VERSION__: JSON.stringify(version)
|
|
|
- }
|
|
|
+ __VERSION__: JSON.stringify(version),
|
|
|
+ },
|
|
|
});
|
|
|
};
|