mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-06 08:32:51 +08:00
✨ fear(build): 添加打包时间显示
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
|
||||
import sqlite3 from "sqlite3";
|
||||
|
||||
const database = new sqlite3.Database("database.db");
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
import Database from "tauri-plugin-sql-api";
|
||||
|
||||
const dbName = "test.db";
|
||||
const db = await Database.load(`sqlite:${dbName}`);
|
||||
|
||||
await db.execute("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT)");
|
||||
@@ -30,7 +30,7 @@
|
||||
</v-btn>
|
||||
</v-list-item-title>
|
||||
<template #append>
|
||||
<v-list-item-subtitle>{{ versionApp }}</v-list-item-subtitle>
|
||||
<v-list-item-subtitle>{{ versionApp }}.{{ buildTime }}</v-list-item-subtitle>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-list-item title="成就版本">
|
||||
@@ -123,6 +123,7 @@
|
||||
<script lang="ts" setup>
|
||||
// vue
|
||||
import { onMounted, ref } from "vue";
|
||||
import { getBuildTime } from "../utils/TGBuild";
|
||||
import TLoading from "../components/t-loading.vue";
|
||||
import TConfirm from "../components/t-confirm.vue";
|
||||
// tauri
|
||||
@@ -144,6 +145,7 @@ const achievementsStore = useAchievementsStore();
|
||||
// About App
|
||||
const versionApp = ref("" as string);
|
||||
const versionTauri = ref("" as string);
|
||||
const buildTime = ref(getBuildTime());
|
||||
|
||||
// About OS
|
||||
const osPlatform = ref("" as string);
|
||||
|
||||
43
src/utils/TGBuild.ts
Normal file
43
src/utils/TGBuild.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file utils TGBuild.ts
|
||||
* @description 用于获取 vite 打包时间
|
||||
* @see https://gitee.com/lihanspace/vite-plugin-build-time
|
||||
* @author BTMuli<bt-muli@outlook.com>
|
||||
* @since Alpha v0.1.2
|
||||
*/
|
||||
|
||||
import { type Plugin } from "vite";
|
||||
|
||||
const buildTimeKey = "buildTime";
|
||||
|
||||
const buildTimePlugin = (modes: string[] = []): Plugin => {
|
||||
let _mode = "";
|
||||
return {
|
||||
name: "build-time",
|
||||
config (uc, { mode }) {
|
||||
_mode = mode;
|
||||
},
|
||||
transformIndexHtml () {
|
||||
if (_mode !== "production" && !modes.includes(_mode)) return;
|
||||
return [{
|
||||
tag: "script",
|
||||
children: `window.${buildTimeKey} = ${Math.floor(Date.now() / 1000)}`,
|
||||
}];
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getBuildTime = (): string => {
|
||||
if (typeof window === "undefined") {
|
||||
console.warn("getBuildTime() should only be called in the browser");
|
||||
return "dev";
|
||||
}
|
||||
const windowEnv = window as typeof window & { [buildTimeKey]?: string };
|
||||
if (!windowEnv[buildTimeKey]) {
|
||||
console.info("当前环境为开发环境");
|
||||
return `dev.${Math.floor(Date.now() / 1000)}`;
|
||||
}
|
||||
return windowEnv[buildTimeKey];
|
||||
};
|
||||
|
||||
export default buildTimePlugin;
|
||||
@@ -5,5 +5,5 @@
|
||||
"moduleResolution": "Node",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
"include": ["vite.config.ts", "src/utils/TGBuild.ts"]
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
// Vuetify
|
||||
import vuetify from "vite-plugin-vuetify";
|
||||
// build time
|
||||
import buildTimePlugin from "./src/utils/TGBuild";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue(), vuetify()],
|
||||
plugins: [vue(), vuetify(), buildTimePlugin()],
|
||||
|
||||
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
||||
// prevent vite from obscuring rust errors
|
||||
|
||||
Reference in New Issue
Block a user