128 lines
3.2 KiB
TypeScript
128 lines
3.2 KiB
TypeScript
import { theme } from 'antd/lib';
|
|
// @ts-ignore
|
|
import path from 'path';
|
|
import {
|
|
defaultTo,
|
|
toUpper
|
|
} from 'ramda';
|
|
import {
|
|
defineConfig,
|
|
loadEnv
|
|
} from 'vite';
|
|
|
|
import { convertLegacyToken } from '@ant-design/compatible/lib';
|
|
import react from '@vitejs/plugin-react';
|
|
|
|
const { defaultAlgorithm, defaultSeed } = theme;
|
|
|
|
const mapToken = defaultAlgorithm(defaultSeed);
|
|
const v4Token = convertLegacyToken(mapToken);
|
|
|
|
type HostMapping = {
|
|
Host: string;
|
|
Path: string;
|
|
};
|
|
|
|
const EnvHostMapping: { [key: string]: HostMapping } = {
|
|
LOCAL: {
|
|
Host: 'http://localhost:8000',
|
|
// Host: 'http://1.92.72.5:8080/api',
|
|
// Host: 'https://zgd.hbhcbn.com/wxApi',
|
|
Path: ''
|
|
},
|
|
REMOTE: {
|
|
Host: 'https://elec.archgrid.xyz',
|
|
Path: 'api'
|
|
},
|
|
LOCAL_MOCK: {
|
|
Host: 'http://127.0.0.1:4523',
|
|
// Path: '/m1/1411767-0-default'
|
|
Path: '/m1/4143821-0-default'
|
|
}
|
|
};
|
|
|
|
// https://vitejs.dev/config/
|
|
export default mode => {
|
|
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
|
|
const proxyHost: HostMapping = EnvHostMapping[toUpper(defaultTo('LOCAL')(process.env.PROXY_TARGET)).trim()];
|
|
return defineConfig({
|
|
esbuild: {
|
|
define: {
|
|
this: 'window'
|
|
}
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@c': path.resolve(__dirname, 'src', 'components'),
|
|
'@h': path.resolve(__dirname, 'src', 'hooks'),
|
|
'@p': path.resolve(__dirname, 'src', 'pages'),
|
|
'@q': path.resolve(__dirname, 'src', 'queries'),
|
|
'@st': path.resolve(__dirname, 'src', 'states'),
|
|
'@sh': path.resolve(__dirname, 'src', 'shared'),
|
|
'@u': path.resolve(__dirname, 'src', 'utils'),
|
|
'@': path.resolve(__dirname, 'src'),
|
|
'config': path.resolve(__dirname, 'src', 'config'),
|
|
'assets': path.resolve(__dirname, 'src', 'assets')
|
|
}
|
|
},
|
|
build: {
|
|
minify: 'esbuild',
|
|
terserOptions: { compress: true }
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
less: {
|
|
modifyVars: {
|
|
...v4Token,
|
|
'primary-color': '#00B578',
|
|
'menu-bg': 'transparent',
|
|
'menu-inline-submenu-bg': 'transparent',
|
|
'menu-item-color': 'white',
|
|
'table-header-bg': '#00B578',
|
|
'table-header-color': 'white'
|
|
},
|
|
javascriptEnabled: true
|
|
}
|
|
}
|
|
},
|
|
plugins: [
|
|
react({
|
|
babel: {
|
|
plugins: [
|
|
'babel-plugin-macros',
|
|
[
|
|
'@emotion/babel-plugin-jsx-pragmatic',
|
|
{
|
|
export: 'jsx',
|
|
import: '__cssprop',
|
|
module: '@emotion/react'
|
|
}
|
|
],
|
|
['@babel/plugin-transform-react-jsx', { pragma: '__cssprop' }, 'twin.macro']
|
|
]
|
|
}
|
|
})
|
|
],
|
|
envDir: './',
|
|
publicDir: "/user-report",
|
|
base: './',
|
|
server: {
|
|
port: 3000,
|
|
proxy: {
|
|
'/wxApi': {
|
|
target: `${proxyHost.Host}`,
|
|
changeOrigin: true,
|
|
secure: false,
|
|
rewrite: path => path.replace(/^\/wxApi/, proxyHost.Path)
|
|
},
|
|
'/test': {
|
|
target: `http://127.0.0.1:8081`,
|
|
changeOrigin: true,
|
|
secure: false,
|
|
rewrite: path => path.replace(/^\/test/, "")
|
|
}
|
|
}
|
|
}
|
|
});
|
|
};
|