82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import path from 'node:path';
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
|
import type { ConfigEnv, UserConfig } from 'vite';
|
|
import { loadEnv } from 'vite';
|
|
import svgLoader from 'vite-svg-loader';
|
|
|
|
const CWD = process.cwd();
|
|
|
|
// https://vitejs.dev/config/
|
|
export default ({ mode }: ConfigEnv): UserConfig => {
|
|
const { VITE_BASE_URL, VITE_API_URL_PREFIX } = loadEnv(mode, CWD);
|
|
return {
|
|
base: VITE_BASE_URL,
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
|
|
css: {
|
|
preprocessorOptions: {
|
|
less: {
|
|
modifyVars: {
|
|
hack: `true; @import (reference) "${path.resolve('src/style/variables.less')}";`,
|
|
},
|
|
math: 'strict',
|
|
javascriptEnabled: true,
|
|
},
|
|
},
|
|
},
|
|
|
|
plugins: [vue(), vueJsx(), svgLoader()],
|
|
|
|
server: {
|
|
port: 3002,
|
|
host: '0.0.0.0',
|
|
allowedHosts: true,
|
|
proxy: {
|
|
[VITE_API_URL_PREFIX]: {
|
|
target: process.env.VITE_BACKEND_TARGET || 'http://127.0.0.1:18080',
|
|
changeOrigin: false,
|
|
},
|
|
},
|
|
},
|
|
|
|
// https://github.com/vueuse/vueuse/issues/5387#issuecomment-4734186040
|
|
build: {
|
|
rolldownOptions: {
|
|
output: {
|
|
codeSplitting: {
|
|
groups: [
|
|
{
|
|
name: 'tdesign-vendor',
|
|
test: /node_modules[\\/]tdesign-(?:vue-next|icons-vue-next)[\\/]/,
|
|
priority: 30,
|
|
},
|
|
{
|
|
name: 'vue-vendor',
|
|
test: /node_modules[\\/](?:vue|vue-router|pinia|vue-i18n|@vueuse)[\\/]/,
|
|
priority: 20,
|
|
maxSize: 480 * 1024,
|
|
},
|
|
{
|
|
name: 'vendor',
|
|
test: /node_modules[\\/]/,
|
|
priority: 10,
|
|
maxSize: 480 * 1024,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
onLog(level, log, defaultHandler) {
|
|
if (log.code === 'INVALID_ANNOTATION') return null;
|
|
else defaultHandler(level, log);
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|