mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-23 23:39:47 +08:00
build(projects): vite.config代码优化
This commit is contained in:
@ -3,6 +3,6 @@ import dayjs from 'dayjs';
|
||||
/** 项目构建时间 */
|
||||
const PROJECT_BUILD_TIME = JSON.stringify(dayjs().format('YYYY-MM-DD HH:mm:ss'));
|
||||
|
||||
export const define = {
|
||||
export const viteDefine = {
|
||||
PROJECT_BUILD_TIME,
|
||||
};
|
3
build/config/index.ts
Normal file
3
build/config/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './path';
|
||||
export * from './define';
|
||||
export * from './proxy';
|
15
build/config/path.ts
Normal file
15
build/config/path.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
/**
|
||||
* 解析路径
|
||||
* @param basePath - 基础路径
|
||||
*/
|
||||
export function resolvePath(rootPath: string, basePath: string) {
|
||||
const root = fileURLToPath(new URL(rootPath, basePath));
|
||||
const src = `${root}src`;
|
||||
|
||||
return {
|
||||
root,
|
||||
src,
|
||||
};
|
||||
}
|
23
build/config/proxy.ts
Normal file
23
build/config/proxy.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import type { ProxyOptions } from 'vite';
|
||||
import { getEnvConfig } from '../../.env-config';
|
||||
|
||||
/**
|
||||
* 设置网络代理
|
||||
* @param viteEnv
|
||||
*/
|
||||
export function createViteProxy(viteEnv: ImportMetaEnv) {
|
||||
const isOpenProxy = viteEnv.VITE_HTTP_PROXY === 'true';
|
||||
if (!isOpenProxy) return undefined;
|
||||
|
||||
const { http } = getEnvConfig(viteEnv);
|
||||
|
||||
const proxy: Record<string, string | ProxyOptions> = {
|
||||
[http.proxy]: {
|
||||
target: http.url,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(new RegExp(`^${http.proxy}`), ''),
|
||||
},
|
||||
};
|
||||
|
||||
return proxy;
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
export * from './plugins';
|
||||
export * from './define';
|
||||
export * from './config';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { loadEnv } from 'vite';
|
||||
import type { ConfigEnv, PluginOption } from 'vite';
|
||||
import { createHtmlPlugin } from 'vite-plugin-html'; // html插件(使用变量、压缩)
|
||||
import { createHtmlPlugin } from 'vite-plugin-html';
|
||||
|
||||
export default (config: ConfigEnv): PluginOption[] => {
|
||||
const viteEnv = loadEnv(config.mode, `.env.${config.mode}`);
|
||||
|
Reference in New Issue
Block a user