|
@@ -7,26 +7,28 @@ import { createHtmlPlugin } from 'vite-plugin-html';
|
|
|
// import pkg from '../../../package.json';
|
|
// import pkg from '../../../package.json';
|
|
|
// import { GLOB_CONFIG_FILE_NAME } from '../../constant';
|
|
// import { GLOB_CONFIG_FILE_NAME } from '../../constant';
|
|
|
import { simpleGit } from 'simple-git';
|
|
import { simpleGit } from 'simple-git';
|
|
|
|
|
+import dayjs from 'dayjs';
|
|
|
const git = simpleGit();
|
|
const git = simpleGit();
|
|
|
|
|
|
|
|
async function getLatestHash() {
|
|
async function getLatestHash() {
|
|
|
const gitLog = await git.log();
|
|
const gitLog = await git.log();
|
|
|
|
|
+
|
|
|
/** 截取git hash值最后8位 */
|
|
/** 截取git hash值最后8位 */
|
|
|
const lastStrNum = 8;
|
|
const lastStrNum = 8;
|
|
|
return gitLog.latest?.hash.substring(-lastStrNum, lastStrNum);
|
|
return gitLog.latest?.hash.substring(-lastStrNum, lastStrNum);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function getBuildInfo() {
|
|
|
|
|
+ const { current } = await git.branchLocal();
|
|
|
|
|
+ const hash = await getLatestHash();
|
|
|
|
|
+ return { currentBranch: current, hash };
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export function configHtmlPlugin(env: ViteEnv, isBuild: boolean): Promise<PluginOption[]> {
|
|
export function configHtmlPlugin(env: ViteEnv, isBuild: boolean): Promise<PluginOption[]> {
|
|
|
const { VITE_GLOB_APP_TITLE } = env;
|
|
const { VITE_GLOB_APP_TITLE } = env;
|
|
|
|
|
|
|
|
- const path = './';
|
|
|
|
|
-
|
|
|
|
|
- // const getAppConfigSrc = () => {
|
|
|
|
|
- // return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
|
|
|
|
|
- // };
|
|
|
|
|
-
|
|
|
|
|
return new Promise((resolve) => {
|
|
return new Promise((resolve) => {
|
|
|
- getLatestHash().then((hash) => {
|
|
|
|
|
|
|
+ getBuildInfo().then(({ currentBranch, hash }) => {
|
|
|
const htmlPlugin: PluginOption[] = createHtmlPlugin({
|
|
const htmlPlugin: PluginOption[] = createHtmlPlugin({
|
|
|
minify: isBuild,
|
|
minify: isBuild,
|
|
|
inject: {
|
|
inject: {
|
|
@@ -34,7 +36,14 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean): Promise<Plugin
|
|
|
data: {
|
|
data: {
|
|
|
title: VITE_GLOB_APP_TITLE,
|
|
title: VITE_GLOB_APP_TITLE,
|
|
|
hash,
|
|
hash,
|
|
|
|
|
+ injectScript: `
|
|
|
|
|
+ <script type="text/javascript">
|
|
|
|
|
+ console.log("%cbuild branch, ${currentBranch}","background:#1777FF; padding: 3px 6px; border-radius: 4px" )
|
|
|
|
|
+ console.log("%cbuild version: ${hash}", "background:#1777FF; padding: 3px 6px; border-radius: 4px");
|
|
|
|
|
+ console.log("build time, ${dayjs().format('YYYY-MM-DD HH:mm:ss')}", )
|
|
|
|
|
+ </script>`,
|
|
|
},
|
|
},
|
|
|
|
|
+
|
|
|
// // Embed the generated app.config.js file
|
|
// // Embed the generated app.config.js file
|
|
|
// tags: isBuild
|
|
// tags: isBuild
|
|
|
// ? [
|
|
// ? [
|