louhangfei 2 лет назад
Родитель
Сommit
1bad613cd7
3 измененных файлов с 1476 добавлено и 587 удалено
  1. 35 21
      build/vite/plugin/html.ts
  2. 108 103
      index.html
  3. 1333 463
      pnpm-lock.yaml

+ 35 - 21
build/vite/plugin/html.ts

@@ -6,8 +6,17 @@ import type { PluginOption } from 'vite';
 import { createHtmlPlugin } from 'vite-plugin-html';
 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';
+const git = simpleGit();
 
 
-export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
+async function getLatestHash() {
+  const gitLog = await git.log();
+  /** 截取git hash值最后8位 */
+  const lastStrNum = 8;
+  return gitLog.latest?.hash.substring(-lastStrNum, lastStrNum);
+}
+
+export function configHtmlPlugin(env: ViteEnv, isBuild: boolean): Promise<PluginOption[]> {
   const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
   const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
 
 
   const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`;
   const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`;
@@ -16,25 +25,30 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
     return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
     return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
   };
   };
 
 
-  const htmlPlugin: PluginOption[] = createHtmlPlugin({
-    minify: isBuild,
-    inject: {
-      // Inject data into ejs template
-      data: {
-        title: VITE_GLOB_APP_TITLE,
-      },
-      // Embed the generated app.config.js file
-      tags: isBuild
-        ? [
-            {
-              tag: 'script',
-              attrs: {
-                src: getAppConfigSrc(),
-              },
-            },
-          ]
-        : [],
-    },
+  return new Promise((resolve) => {
+    getLatestHash().then((hash) => {
+      const htmlPlugin: PluginOption[] = createHtmlPlugin({
+        minify: isBuild,
+        inject: {
+          // Inject data into ejs template
+          data: {
+            title: VITE_GLOB_APP_TITLE,
+            hash,
+          },
+          // Embed the generated app.config.js file
+          tags: isBuild
+            ? [
+                {
+                  tag: 'script',
+                  attrs: {
+                    src: getAppConfigSrc(),
+                  },
+                },
+              ]
+            : [],
+        },
+      });
+      resolve(htmlPlugin);
+    });
   });
   });
-  return htmlPlugin;
 }
 }

+ 108 - 103
index.html

@@ -1,121 +1,126 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
 <html lang="zh-cmn-Hans" id="htmlRoot" data-theme="light">
 <html lang="zh-cmn-Hans" id="htmlRoot" data-theme="light">
+
 <head>
 <head>
-  <meta charset="UTF-8">
-  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"/>
-  <meta content="webkit" name="renderer"/>
-  <meta
-    content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
-    name="viewport"
-  />
-  <link href="/favicon.ico" rel="icon"/>
-  <title><%= title %></title>
+  <meta charset="UTF-8" />
+  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
+  <meta content="webkit" name="renderer" />
+  <meta content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
+    name="viewport" />
+  <link href="/favicon.ico" rel="icon" />
+  <title>
+    <%= title %>
+  </title>
 </head>
 </head>
+
 <body>
 <body>
-<div id="app">
-  <style>
-  .first-loading-wrap {
-    display: flex;
-    width: 100%;
-    height: 100vh;
-    justify-content: center;
-    align-items: center;
-    flex-direction: column;
-  }
+  <div id="app">
+    <style>
+      .first-loading-wrap {
+        display: flex;
+        width: 100%;
+        height: 100vh;
+        justify-content: center;
+        align-items: center;
+        flex-direction: column;
+      }
 
 
-  .first-loading-wrap > h1 {
-    font-size: 128px
-  }
+        .first-loading-wrap > h1 {
+          font-size: 128px;
+        }
 
 
-  .first-loading-wrap .loading-wrap {
-    padding: 98px;
-    display: flex;
-    justify-content: center;
-    align-items: center
-  }
+      .first-loading-wrap .loading-wrap {
+        padding: 98px;
+        display: flex;
+        justify-content: center;
+        align-items: center;
+      }
 
 
-  .dot {
-    animation: antRotate 1.2s infinite linear;
-    transform: rotate(45deg);
-    position: relative;
-    display: inline-block;
-    font-size: 32px;
-    width: 32px;
-    height: 32px;
-    box-sizing: border-box
-  }
+        .dot {
+          animation: antRotate 1.2s infinite linear;
+          transform: rotate(45deg);
+          position: relative;
+          display: inline-block;
+          font-size: 32px;
+          width: 32px;
+          height: 32px;
+          box-sizing: border-box;
+        }
 
 
-  .dot i {
-    width: 14px;
-    height: 14px;
-    position: absolute;
-    display: block;
-    background-color: #1890ff;
-    border-radius: 100%;
-    transform: scale(.75);
-    transform-origin: 50% 50%;
-    opacity: .3;
-    animation: antSpinMove 1s infinite linear alternate
-  }
+        .dot i {
+          width: 14px;
+          height: 14px;
+          position: absolute;
+          display: block;
+          background-color: #1890ff;
+          border-radius: 100%;
+          transform: scale(0.75);
+          transform-origin: 50% 50%;
+          opacity: 0.3;
+          animation: antSpinMove 1s infinite linear alternate;
+        }
 
 
-  .dot i:nth-child(1) {
-    top: 0;
-    left: 0
-  }
+        .dot i:nth-child(1) {
+          top: 0;
+          left: 0;
+        }
 
 
-  .dot i:nth-child(2) {
-    top: 0;
-    right: 0;
-    -webkit-animation-delay: .4s;
-    animation-delay: .4s
-  }
+        .dot i:nth-child(2) {
+          top: 0;
+          right: 0;
+          -webkit-animation-delay: 0.4s;
+          animation-delay: 0.4s;
+        }
 
 
-  .dot i:nth-child(3) {
-    right: 0;
-    bottom: 0;
-    -webkit-animation-delay: .8s;
-    animation-delay: .8s
-  }
+        .dot i:nth-child(3) {
+          right: 0;
+          bottom: 0;
+          -webkit-animation-delay: 0.8s;
+          animation-delay: 0.8s;
+        }
 
 
-  .dot i:nth-child(4) {
-    bottom: 0;
-    left: 0;
-    -webkit-animation-delay: 1.2s;
-    animation-delay: 1.2s
-  }
+        .dot i:nth-child(4) {
+          bottom: 0;
+          left: 0;
+          -webkit-animation-delay: 1.2s;
+          animation-delay: 1.2s;
+        }
 
 
-  @keyframes antRotate {
-    to {
-      -webkit-transform: rotate(405deg);
-      transform: rotate(405deg)
-    }
-  }
+        @keyframes antRotate {
+          to {
+            -webkit-transform: rotate(405deg);
+            transform: rotate(405deg);
+          }
+        }
 
 
-  @-webkit-keyframes antRotate {
-    to {
-      -webkit-transform: rotate(405deg);
-      transform: rotate(405deg)
-    }
-  }
+        @-webkit-keyframes antRotate {
+          to {
+            -webkit-transform: rotate(405deg);
+            transform: rotate(405deg);
+          }
+        }
 
 
-  @keyframes antSpinMove {
-    to {
-      opacity: 1
-    }
-  }
+        @keyframes antSpinMove {
+          to {
+            opacity: 1;
+          }
+        }
 
 
-  @-webkit-keyframes antSpinMove {
-    to {
-      opacity: 1
-    }
-  }</style>
-  <div class="first-loading-wrap">
-    <div class="loading-wrap">
-      <span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
+        @-webkit-keyframes antSpinMove {
+          to {
+            opacity: 1;
+          }
+        }
+      </style>
+      <div class="first-loading-wrap">
+        <div class="loading-wrap">
+          <span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
+        </div>
+      </div>
     </div>
     </div>
-  </div>
-</div>
-<script>var globalThis = window;</script> 
-<script src="/src/main.ts" type="module"></script>
-</body>
-</html>
+    <script>
+      var globalThis = window;
+    </script>
+    <script src="/src/main.ts" type="module"></script>
+  </body>
+</html>

Разница между файлами не показана из-за своего большого размера
+ 1333 - 463
pnpm-lock.yaml