mirror of
https://github.com/Tencent/tdesign-vue-next-starter.git
synced 2024-11-10 07:28:24 +08:00
2a9e3722b8
1. 修复环境变量类型丢失 2. 修改错误变量名写法 3. 调整配置顺序,将常用配置向上移动 4. 将配置项抽出到环境变量文件 5. 对环境变量进行注释描述类型补全 6. 环境变量文件解耦,防止排错成本增加
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import path from 'node:path';
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
import { ConfigEnv, loadEnv, UserConfig } from 'vite';
|
|
import { viteMockServe } from 'vite-plugin-mock';
|
|
import svgLoader from 'vite-svg-loader';
|
|
|
|
const cwd = process.cwd();
|
|
|
|
// https://vitejs.dev/config/
|
|
export default ({ mode }: ConfigEnv): UserConfig => {
|
|
const { VITE_BASE_PORT, VITE_BASE_URL, VITE_USE_MOCK, VITE_API_URL, VITE_API_URL_PREFIX }: Partial<ImportMetaEnv> =
|
|
loadEnv(mode, cwd);
|
|
return {
|
|
base: VITE_BASE_URL,
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
server: {
|
|
port: Number(VITE_BASE_PORT),
|
|
host: '0.0.0.0',
|
|
proxy: {
|
|
[VITE_API_URL_PREFIX]: VITE_API_URL,
|
|
},
|
|
},
|
|
plugins: [
|
|
vue(),
|
|
vueJsx(),
|
|
viteMockServe({
|
|
mockPath: 'mock',
|
|
enable: VITE_USE_MOCK === 'true',
|
|
}),
|
|
svgLoader(),
|
|
],
|
|
css: {
|
|
preprocessorOptions: {
|
|
less: {
|
|
modifyVars: {
|
|
hack: `true; @import (reference) "${path.resolve('src/style/variables.less')}";`,
|
|
},
|
|
math: 'strict',
|
|
javascriptEnabled: true,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|