2025-07-02 15:30:13 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* @Author: RenXiaoDong
|
|
|
|
|
|
* @Date: 2025-07-02 09:17:39
|
|
|
|
|
|
*/
|
2025-06-16 14:42:26 +08:00
|
|
|
|
import type { ConfigEnv, UserConfig } from 'vite';
|
|
|
|
|
|
|
|
|
|
|
|
import { defineConfig, loadEnv } from 'vite';
|
|
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
|
|
|
|
import analyzer from 'rollup-plugin-visualizer';
|
|
|
|
|
|
|
|
|
|
|
|
import { pluginsConfig, setServerConfig, resolve } from './config';
|
|
|
|
|
|
|
|
|
|
|
|
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
|
|
|
|
|
const envDir = resolve('env');
|
|
|
|
|
|
const env = loadEnv(mode, envDir, '');
|
|
|
|
|
|
const setServer = setServerConfig({ env });
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
css: {
|
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
|
scss: {
|
2025-07-02 15:30:13 +08:00
|
|
|
|
// additionalData: `@import "@/styles/vars.css";`,
|
2025-06-16 14:42:26 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
plugins: [vue(), vueJsx(), ...pluginsConfig, setAnalyzer(env.VITE_ENV)],
|
|
|
|
|
|
resolve: {
|
|
|
|
|
|
extensions: ['.jsx', '.tsx', '.js', '.ts', '.json', '.vue'],
|
|
|
|
|
|
alias: {
|
|
|
|
|
|
'@': resolve('src'),
|
|
|
|
|
|
'@components': resolve('src/components'),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
envDir,
|
|
|
|
|
|
envPrefix: env.ENV_PREFIX,
|
|
|
|
|
|
server: {
|
|
|
|
|
|
proxy: {
|
|
|
|
|
|
'/api': {
|
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
|
rewrite: (path) => path.replace(/^\/api/, ''),
|
|
|
|
|
|
// 目标地址
|
2025-07-04 14:05:01 +08:00
|
|
|
|
target: 'http://192.168.40.3/api',
|
2025-07-02 15:30:13 +08:00
|
|
|
|
// target: 'https://lingjiapi.lvfunai.com/api',
|
2025-06-16 14:42:26 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
preview: setServer(),
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置分析器,仅在development环境下生效
|
|
|
|
|
|
* @param env
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
function setAnalyzer(env = 'development') {
|
|
|
|
|
|
console.log('env: ', env);
|
|
|
|
|
|
if (env === 'development') {
|
|
|
|
|
|
return analyzer({
|
|
|
|
|
|
filename: 'analyzer.html',
|
|
|
|
|
|
open: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|