mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-09-07 20:58:11 +00:00
perf: Refactor vite configuration
This commit is contained in:
109
vite.config.ts
109
vite.config.ts
@@ -1,95 +1,24 @@
|
||||
import type { UserConfig, ConfigEnv } from 'vite';
|
||||
import pkg from './package.json';
|
||||
import dayjs from 'dayjs';
|
||||
import { loadEnv } from 'vite';
|
||||
import { resolve } from 'path';
|
||||
import { generateModifyVars } from './build/generate/generateModifyVars';
|
||||
import { createProxy } from './build/vite/proxy';
|
||||
import { wrapperEnv } from './build/utils';
|
||||
import { createVitePlugins } from './build/vite/plugin';
|
||||
import { OUTPUT_DIR } from './build/constant';
|
||||
import { defineApplicationConfig } from '@vben/vite-config';
|
||||
|
||||
function pathResolve(dir: string) {
|
||||
return resolve(process.cwd(), '.', dir);
|
||||
}
|
||||
|
||||
const { dependencies, devDependencies, name, version } = pkg;
|
||||
const __APP_INFO__ = {
|
||||
pkg: { dependencies, devDependencies, name, version },
|
||||
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||
};
|
||||
|
||||
export default async ({ command, mode }: ConfigEnv): Promise<UserConfig> => {
|
||||
const root = process.cwd();
|
||||
|
||||
const env = loadEnv(mode, root);
|
||||
|
||||
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
|
||||
const viteEnv = wrapperEnv(env);
|
||||
|
||||
const { VITE_PUBLIC_PATH, VITE_PROXY } = viteEnv;
|
||||
|
||||
const isBuild = command === 'build';
|
||||
|
||||
return {
|
||||
base: VITE_PUBLIC_PATH,
|
||||
root,
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: 'vue-i18n',
|
||||
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
|
||||
},
|
||||
// /@/xxxx => src/xxxx
|
||||
{
|
||||
find: /\/@\//,
|
||||
replacement: pathResolve('src') + '/',
|
||||
},
|
||||
// /#/xxxx => types/xxxx
|
||||
{
|
||||
find: /\/#\//,
|
||||
replacement: pathResolve('types') + '/',
|
||||
},
|
||||
],
|
||||
},
|
||||
export default defineApplicationConfig({
|
||||
overrides: {
|
||||
server: {
|
||||
host: true,
|
||||
// Load proxy configuration from .env
|
||||
proxy: createProxy(VITE_PROXY),
|
||||
},
|
||||
esbuild: {
|
||||
drop: ['console', 'debugger'],
|
||||
},
|
||||
build: {
|
||||
target: 'es2015',
|
||||
cssTarget: 'chrome80',
|
||||
outDir: OUTPUT_DIR,
|
||||
reportCompressedSize: false,
|
||||
chunkSizeWarningLimit: 2000,
|
||||
},
|
||||
define: {
|
||||
__APP_INFO__: JSON.stringify(__APP_INFO__),
|
||||
},
|
||||
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
less: {
|
||||
modifyVars: generateModifyVars(),
|
||||
javascriptEnabled: true,
|
||||
proxy: {
|
||||
'/basic-api': {
|
||||
target: 'http://localhost:3000',
|
||||
changeOrigin: true,
|
||||
ws: true,
|
||||
rewrite: (path) => path.replace(new RegExp(`^/basic-api`), ''),
|
||||
// only https
|
||||
// secure: false
|
||||
},
|
||||
'/upload': {
|
||||
target: 'http://localhost:3300/upload',
|
||||
changeOrigin: true,
|
||||
ws: true,
|
||||
rewrite: (path) => path.replace(new RegExp(`^/upload`), ''),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
|
||||
plugins: await createVitePlugins(viteEnv, isBuild),
|
||||
|
||||
optimizeDeps: {
|
||||
// @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
|
||||
include: [
|
||||
'@iconify/iconify',
|
||||
'ant-design-vue/es/locale/zh_CN',
|
||||
'ant-design-vue/es/locale/en_US',
|
||||
],
|
||||
},
|
||||
};
|
||||
};
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user