perf: 优化项目构建相关函数

This commit is contained in:
xiaoxian521
2024-01-08 16:50:54 +08:00
parent a114dbb465
commit e64cd0c8df
4 changed files with 84 additions and 62 deletions

View File

@@ -1,30 +1,13 @@
import dayjs from "dayjs";
import { resolve } from "path";
import pkg from "./package.json";
import { warpperEnv } from "./build";
import { getPluginsList } from "./build/plugins";
import { include, exclude } from "./build/optimize";
import { type UserConfigExport, type ConfigEnv, loadEnv } from "vite";
/** 当前执行node命令时文件夹的地址工作目录 */
const root: string = process.cwd();
/** 路径查找 */
const pathResolve = (dir: string): string => {
return resolve(__dirname, ".", dir);
};
/** 设置别名 */
const alias: Record<string, string> = {
"@": pathResolve("src"),
"@build": pathResolve("build")
};
const { dependencies, devDependencies, name, version } = pkg;
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version },
lastBuildTime: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss")
};
import {
root,
alias,
warpperEnv,
pathResolve,
__APP_INFO__
} from "./build/utils";
export default ({ mode }: ConfigEnv): UserConfigExport => {
const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } =
@@ -61,7 +44,7 @@ export default ({ mode }: ConfigEnv): UserConfigExport => {
chunkSizeWarningLimit: 4000,
rollupOptions: {
input: {
index: pathResolve("index.html")
index: pathResolve("./index.html", import.meta.url)
},
// 静态资源分类打包
output: {