Compare commits

..

No commits in common. "1dd9e97a43186ad9f3767faea2fd87dd772e3833" and "4a12220476aa4a3f6dcf506c737d7b2707736f4e" have entirely different histories.

10 changed files with 72 additions and 153 deletions

10
.env
View File

@ -1,8 +1,2 @@
# 线上环境接口地址 # 请求api地址
VITE_APP_URL="http://localhost:8800" BUNNY_APP_URL=http://localhost:8088/xxx
# 线上环境接口地址
VITE_APP_MOCK_URL="http://localhost:8800"
# 端口号
VITE_APP_PORT=6262
# 是否使用CDN加速
VITE_CDN=true

View File

@ -1,8 +1,2 @@
# 线上环境接口地址 # 请求api地址
VITE_APP_URL="http://localhost:8800" BUNNY_APP_URL=http://localhost:8088/development
# 线上环境接口地址
VITE_APP_MOCK_URL="http://localhost:8800"
# 端口号
VITE_APP_PORT=6262
# 是否使用CDN加速
VITE_CDN=true

View File

@ -1,8 +1,2 @@
# 线上环境接口地址 # 请求api地址
VITE_APP_URL="http://localhost:8800" BUNNY_APP_URL=http://localhost:8088/prod
# 线上环境接口地址
VITE_APP_MOCK_URL="http://localhost:8800"
# 端口号
VITE_APP_PORT=6262
# 是否使用CDN加速
VITE_CDN=true

View File

@ -10,9 +10,9 @@ dayjs.extend(duration);
const welcomeMessage = gradientString('cyan', 'magenta').multiline( const welcomeMessage = gradientString('cyan', 'magenta').multiline(
`您好! 欢迎使用 bunny-admin 后台管理 `您好! 欢迎使用 bunny-admin 后台管理
访 访
http://localhost:6262/ http://localhost:8202/
访 访
http://localhost:6262/`, http://localhost:8202/`,
); );
const boxenOptions: BoxenOptions = { const boxenOptions: BoxenOptions = {

View File

@ -8,6 +8,7 @@ import { viteMockServe } from 'vite-plugin-mock';
import { viteBuildInfo } from './info'; import { viteBuildInfo } from './info';
export function getPluginsList(): PluginOption[] { export function getPluginsList(): PluginOption[] {
const lifecycle = process.env.npm_lifecycle_event;
return [ return [
vue(), vue(),
legacy({ legacy({
@ -36,7 +37,7 @@ export function getPluginsList(): PluginOption[] {
vueJsx(), vueJsx(),
compression(), compression(),
viteBuildInfo(), viteBuildInfo(),
process.env.VITE_CDN ? cdn : null, cdn,
viteMockServe({ mockPath: 'src/mock' }), viteMockServe({ mockPath: 'src/mock' }),
]; ];
} }

View File

@ -8,12 +8,12 @@ export const serverOptions = () => {
cors: true, cors: true,
proxy: { proxy: {
'/api': { '/api': {
target: process.env.VITE_APP_URL, target: process.env.BUNNY_APP_URL,
changeOrigin: true, changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/api/, '/api'), rewrite: (path: string) => path.replace(/^\/api/, '/api'),
}, },
'/mock': { '/mock': {
target: process.env.VITE_APP_MOCK_URL, target: process.env.BUNNY_APP_URL,
changeOrigin: true, changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/mock/, '/mock'), rewrite: (path: string) => path.replace(/^\/mock/, '/mock'),
}, },

View File

@ -1,15 +1,10 @@
import { readdir, stat } from 'node:fs'; import { readdir, stat } from 'node:fs';
import { formatBytes, Recordable, sum } from '@pureadmin/utils'; import { formatBytes, sum } from '@pureadmin/utils';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
/** 启动`node`进程时所在工作目录的绝对路径 */
const root: string = process.cwd();
const fileListTotal: number[] = []; const fileListTotal: number[] = [];
/** 获取指定文件夹中所有文件的总大小 */ /** 获取指定文件夹中所有文件的总大小 */
const getPackageSize = (options: any) => { const getPackageSize = options => {
const { folder = 'dist', callback, format = true } = options; const { folder = 'dist', callback, format = true } = options;
readdir(folder, (err, files: string[]) => { readdir(folder, (err, files: string[]) => {
if (err) throw err; if (err) throw err;
@ -35,53 +30,4 @@ const getPackageSize = (options: any) => {
}); });
}; };
/** export { getPackageSize };
* @description
* @param dir `build`
* @param metaUrl `url``build``import.meta.url`
*/
const pathResolve = (dir = '.', metaUrl = import.meta.url) => {
// 当前文件目录的绝对路径
const currentFileDir = dirname(fileURLToPath(metaUrl));
// build 目录的绝对路径
const buildDir = resolve(currentFileDir, 'build');
// 解析的绝对路径
const resolvedPath = resolve(currentFileDir, dir);
// 检查解析的绝对路径是否在 build 目录内
if (resolvedPath.startsWith(buildDir)) {
// 在 build 目录内,返回当前文件路径
return fileURLToPath(metaUrl);
}
// 不在 build 目录内,返回解析后的绝对路径
return resolvedPath;
};
/** 处理环境变量 */
const wrapperEnv = (envConf: Recordable): any => {
// TODO 默认值
const ret: any = {
VITE_APP_PORT: 6262,
VITE_APP_URL: '',
VITE_APP_MOCK_URL: '',
VITE_CDN: false,
};
for (const envName of Object.keys(envConf)) {
let realName = envConf[envName].replace(/\\n/g, '\n');
realName = realName === 'true' ? true : realName === 'false' ? false : realName;
if (envName === 'VITE_PORT') {
realName = Number(realName);
}
ret[envName] = realName;
if (typeof realName === 'string') {
process.env[envName] = realName;
} else if (typeof realName === 'object') {
process.env[envName] = JSON.stringify(realName);
}
}
return ret;
};
export { getPackageSize, pathResolve, root, wrapperEnv };

View File

@ -1,55 +1,50 @@
{ {
"compilerOptions": { "compilerOptions": {
// any // any
"noImplicitAny": false, "noImplicitAny": false,
"target": "ES2020", "target": "ES2020",
"useDefineForClassFields": true, "useDefineForClassFields": true,
"module": "ESNext", "module": "ESNext",
"lib": [ "lib": [
"ES2020", "ES2020",
"DOM", "DOM",
"DOM.Iterable" "DOM.Iterable"
], ],
"baseUrl": ".", "baseUrl": ".",
"skipLibCheck": true, "skipLibCheck": true,
"types": [ "types": [
// "webpack-env" // "webpack-env"
"node" "node"
], ],
"paths": { "paths": {
"@/*": [ "@/*": [
"src/*" "src/*"
], ]
"@build/*": [ },
"build/*" /* Bundler mode */
] "moduleResolution": "bundler",
}, "allowImportingTsExtensions": true,
/* Bundler mode */ "resolveJsonModule": true,
"moduleResolution": "bundler", "isolatedModules": true,
"allowImportingTsExtensions": true, "noEmit": true,
"resolveJsonModule": true, "jsx": "preserve",
"isolatedModules": true, /* Linting */
"noEmit": true, "strict": true,
"jsx": "preserve", "noUnusedLocals": true,
/* Linting */ "noUnusedParameters": true,
"strict": true, "noFallthroughCasesInSwitch": true
"noUnusedLocals": true, },
"noUnusedParameters": true, "include": [
"noFallthroughCasesInSwitch": true "src/**/*.ts",
}, "src/**/*.tsx",
"include": [ "src/**/*.vue"
"src/**/*.ts", ],
"src/**/*.tsx", "exclude": [
"src/**/*.vue", "node_modules"
"build/*.ts", ],
"vite.config.ts" "references": [
], {
"exclude": [ "path": "./tsconfig.node.json"
"node_modules" }
], ]
"references": [
{
"path": "./tsconfig.node.json"
}
]
} }

View File

@ -7,7 +7,5 @@
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"strict": true "strict": true
}, },
"include": [ "include": ["vite.config.ts"]
"vite.config.ts"
]
} }

View File

@ -1,20 +1,17 @@
import { resolve } from 'path'; import { resolve } from 'path';
import { ConfigEnv, UserConfigExport } from 'vite'; import { defineConfig, UserConfig } from 'vite';
import { getPluginsList } from './build/plugins';
import { buildEnvironment } from './build/buildEnv'; import { buildEnvironment } from './build/buildEnv';
import { serverOptions } from './build/server';
import { exclude, include } from './build/optimize'; import { exclude, include } from './build/optimize';
import { pathResolve } from './build/utils.ts'; import { getPluginsList } from './build/plugins';
import { serverOptions } from './build/server';
export default ({ mode }: ConfigEnv): UserConfigExport => { export default defineConfig(
// const { VITE_APP_URL } = wrapperEnv(loadEnv(mode, root)); (): UserConfig => ({
envPrefix: 'BUNNY',
return {
resolve: { resolve: {
alias: { alias: {
'@': resolve(__dirname, './src'), '@': resolve(__dirname, './src'),
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js', 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
'@build': pathResolve(),
}, },
}, },
optimizeDeps: { include, exclude }, optimizeDeps: { include, exclude },
@ -28,5 +25,5 @@ export default ({ mode }: ConfigEnv): UserConfigExport => {
}, },
// 配置构建过程的选项,例如是否生成压缩文件和源映射 // 配置构建过程的选项,例如是否生成压缩文件和源映射
build: buildEnvironment(), build: buildEnvironment(),
}; }),
}; );