build: 📦 定义vite全局常量替换

This commit is contained in:
cshaptx4869
2024-03-05 21:03:49 +08:00
parent ba384ab965
commit 4732c23767
3 changed files with 37 additions and 3 deletions

View File

@@ -13,6 +13,19 @@ import mockDevServerPlugin from "vite-plugin-mock-dev-server";
import UnoCSS from "unocss/vite";
import { resolve } from "path";
import {
name,
version,
engines,
dependencies,
devDependencies,
} from "./package.json";
/** 平台的名称、版本、运行所需的`node`版本、依赖、构建时间的类型提示 */
const __APP_INFO__ = {
pkg: { name, version, engines, dependencies, devDependencies },
buildTimestamp: Date.now(),
};
const pathSrc = resolve(__dirname, "src");
// https://cn.vitejs.dev/config
@@ -217,5 +230,8 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
},
},
},
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__),
},
};
});