diff --git a/web/build/utils.ts b/web/build/utils.ts index 15c90526..949bed3b 100644 --- a/web/build/utils.ts +++ b/web/build/utils.ts @@ -1,5 +1,11 @@ +import childProcess from 'child_process'; + /** * workbox 匹配plugin的缓存 */ export const workboxPluginPattern = /plugins\/com\.msgbyte(.*?)\/((?!index).)*?\.js/; + +export function getCommitHash(): string { + return String(childProcess.execSync('git rev-parse HEAD')); +} diff --git a/web/build/webpack.config.ts b/web/build/webpack.config.ts index d8a568a2..16857d48 100644 --- a/web/build/webpack.config.ts +++ b/web/build/webpack.config.ts @@ -13,7 +13,8 @@ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import fs from 'fs'; import WorkboxPlugin from 'workbox-webpack-plugin'; -import { workboxPluginPattern } from './utils'; +import { getCommitHash, workboxPluginPattern } from './utils'; +import dayjs from 'dayjs'; // eslint-disable-next-line @typescript-eslint/no-var-requires require('dotenv').config(); @@ -45,7 +46,9 @@ const plugins: Configuration['plugins'] = [ 'process.env.NODE_ENV': JSON.stringify(NODE_ENV), 'process.env.SERVICE_URL': JSON.stringify(process.env.SERVICE_URL), 'process.env.VERSION': JSON.stringify( - process.env.VERSION || packageJson.version + `${process.env.VERSION || packageJson.version}-${dayjs().format( + 'YYYYMMDD' + )}-${getCommitHash()}` ), }), new HtmlWebpackPlugin({