optimize: ♻️ 自动更新访问地址 #9

Merged
bunny merged 1 commits from dev into master 2024-07-01 08:34:22 +08:00
8 changed files with 34 additions and 33 deletions

View File

@ -1,18 +1,18 @@
import type { Plugin } from 'vite';
import { getPackageSize } from './utils';
import boxen, { type Options as BoxenOptions } from 'boxen';
import dayjs, { type Dayjs } from 'dayjs';
import duration from 'dayjs/plugin/duration';
import gradientString from 'gradient-string';
import boxen, { type Options as BoxenOptions } from 'boxen';
import type { Plugin } from 'vite';
import { loadEnv } from 'vite';
import { getPackageSize, root, wrapperEnv } from './utils';
dayjs.extend(duration);
const { VITE_PORT } = wrapperEnv(loadEnv('dev', root));
const welcomeMessage = gradientString('cyan', 'magenta').multiline(
`您好! 欢迎使用 bunny-admin 后台管理
访
http://localhost:6262/
访
http://localhost:6262/`,
`您好! 欢迎使用 bunny 系列开发模板
访
http://localhost:${VITE_PORT}`,
);
const boxenOptions: BoxenOptions = {
@ -44,7 +44,14 @@ export function viteBuildInfo(): Plugin {
getPackageSize({
folder: outDir,
callback: (size: string) => {
console.log(boxen(gradientString('cyan', 'magenta').multiline(`🎉 恭喜打包完成(总用时${dayjs.duration(endTime.diff(startTime)).format('mm分ss秒')},打包后的大小为${size}`), boxenOptions));
console.log(
boxen(
gradientString('cyan', 'magenta').multiline(
`🎉 恭喜打包完成(总用时${dayjs.duration(endTime.diff(startTime)).format('mm分ss秒')},打包后的大小为${size}`,
),
boxenOptions,
),
);
},
});
}

View File

@ -1,19 +1,22 @@
import { type ServerOptions } from 'vite';
import { loadEnv, type ServerOptions } from 'vite';
import { root, wrapperEnv } from './utils';
export const serverOptions = (mode: string) => {
const { VITE_APP_URL, VITE_APP_MOCK_URL, VITE_PORT } = wrapperEnv(loadEnv(mode, root));
export const serverOptions = () => {
const options: ServerOptions = {
port: 6261,
port: VITE_PORT,
host: '0.0.0.0',
open: true,
cors: true,
proxy: {
'/api': {
target: process.env.VITE_APP_URL,
target: VITE_APP_URL,
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/api/, '/api'),
},
'/mock': {
target: process.env.VITE_APP_MOCK_URL,
target: VITE_APP_MOCK_URL,
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/mock/, '/mock'),
},

View File

@ -1,7 +1,7 @@
import { Recordable, formatBytes, sum } from '@pureadmin/utils';
import { readdir, stat } from 'node:fs';
import { formatBytes, Recordable, sum } from '@pureadmin/utils';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
/** 启动`node`进程时所在工作目录的绝对路径 */
const root: string = process.cwd();

View File

@ -1,9 +1,8 @@
import Request from "@/service/request-mock.ts";
import Request from '@/api/service/request-mock.ts';
export const fetchGetI18n = () => {
return Request({
url: "/getI18n",
method: "GET"
});
return Request({
url: '/getI18n',
method: 'GET',
});
};

View File

@ -1,4 +1,4 @@
import { ResultEnum } from '@/enums/httpEnum';
import { ResultEnum } from '@/enums/httpEnum.ts';
import axios from 'axios';
const request = axios.create({

View File

@ -1,4 +1,4 @@
import { ResultEnum } from '@/enums/httpEnum';
import { ResultEnum } from '@/enums/httpEnum.ts';
import axios from 'axios';
const request = axios.create({

View File

@ -1,8 +0,0 @@
import Request from '@/service/request';
export const reqGetLoadBoard = () => {
return Request({
url: '/board/loadBoard',
method: 'GET',
});
};

View File

@ -1,4 +1,4 @@
import Request from '@/service/request';
import Request from '@/api/service/request';
export const reqGetLoadBoard = () => {
return Request({