first commit
This commit is contained in:
61
vite.config.ts
Normal file
61
vite.config.ts
Normal file
@ -0,0 +1,61 @@
|
||||
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: {
|
||||
additionalData: `@import "@/styles/vars.css";`,
|
||||
},
|
||||
},
|
||||
},
|
||||
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/, ''),
|
||||
// 目标地址
|
||||
target: 'https://lingjiapi.lvfunai.com/api',
|
||||
},
|
||||
},
|
||||
},
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user