mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-12-09 14:40:27 +08:00
feat: add farm startup mode
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { Plugin } from "vite";
|
||||
import { getPackageSize } from "./utils";
|
||||
import dayjs, { type Dayjs } from "dayjs";
|
||||
import duration from "dayjs/plugin/duration";
|
||||
import duration from "dayjs/plugin/duration.js";
|
||||
import gradientString from "gradient-string";
|
||||
import boxen, { type Options as BoxenOptions } from "boxen";
|
||||
dayjs.extend(duration);
|
||||
|
||||
@@ -19,13 +19,18 @@ export function getPluginsList(
|
||||
VITE_COMPRESSION: ViteCompression
|
||||
): PluginOption[] {
|
||||
const lifecycle = process.env.npm_lifecycle_event;
|
||||
|
||||
return [
|
||||
vue(),
|
||||
// jsx、tsx语法支持
|
||||
vueJsx(),
|
||||
VueI18nPlugin({
|
||||
runtimeOnly: true,
|
||||
jitCompilation: false,
|
||||
include: [pathResolve("../locales/**")]
|
||||
compositionOnly: true,
|
||||
include: [
|
||||
pathResolve(process.env.FARM_FE ? "./locales/**" : "../locales/**")
|
||||
]
|
||||
}),
|
||||
viteBuildInfo(),
|
||||
/**
|
||||
@@ -53,7 +58,9 @@ export function getPluginsList(
|
||||
VITE_CDN ? cdn : null,
|
||||
configCompressPlugin(VITE_COMPRESSION),
|
||||
// 线上环境删除console
|
||||
removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
|
||||
process.env.FARM_FE
|
||||
? null
|
||||
: removeConsole({ external: ["src/assets/iconfont/iconfont.js"] }),
|
||||
// 打包分析
|
||||
lifecycle === "report"
|
||||
? visualizer({ open: true, brotliSize: true, filename: "report.html" })
|
||||
|
||||
@@ -19,7 +19,23 @@ const root: string = process.cwd();
|
||||
* @param dir 路径片段,默认`build`
|
||||
* @param metaUrl 模块的完整`url`,如果在`build`目录外调用必传`import.meta.url`
|
||||
*/
|
||||
const pathResolve = (dir = ".", metaUrl = import.meta.url) => {
|
||||
const pathResolveFarm = (dir = ".", metaUrl = root) => {
|
||||
// 当前文件目录的绝对路径
|
||||
const currentFileDir = 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 pathResolveVite = (dir = ".", metaUrl = import.meta.url) => {
|
||||
// 当前文件目录的绝对路径
|
||||
const currentFileDir = dirname(fileURLToPath(metaUrl));
|
||||
// build 目录的绝对路径
|
||||
@@ -35,15 +51,18 @@ const pathResolve = (dir = ".", metaUrl = import.meta.url) => {
|
||||
return resolvedPath;
|
||||
};
|
||||
|
||||
const pathResolve = process.env.FARM_FE ? pathResolveFarm : pathResolveVite;
|
||||
|
||||
/** 设置别名 */
|
||||
const alias: Record<string, string> = {
|
||||
"@": pathResolve("../src"),
|
||||
"@": pathResolve(process.env.FARM_FE ? "src" : "../src"),
|
||||
"@build": pathResolve()
|
||||
};
|
||||
|
||||
/** 平台的名称、版本、运行所需的`node`和`pnpm`版本、依赖、最后构建时间的类型提示 */
|
||||
const __APP_INFO__ = {
|
||||
pkg: { name, version, engines, dependencies, devDependencies },
|
||||
// lastBuildTime: "2024-03-24 14:39:02"
|
||||
lastBuildTime: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss")
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user