chore: 修改打包时version生成逻辑

pull/81/head
moonrailgun 4 years ago
parent 5caaa978f0
commit 2dcd4d0976

@ -1,5 +1,11 @@
import childProcess from 'child_process';
/** /**
* workbox plugin * workbox plugin
*/ */
export const workboxPluginPattern = export const workboxPluginPattern =
/plugins\/com\.msgbyte(.*?)\/((?!index).)*?\.js/; /plugins\/com\.msgbyte(.*?)\/((?!index).)*?\.js/;
export function getCommitHash(): string {
return String(childProcess.execSync('git rev-parse HEAD'));
}

@ -13,7 +13,8 @@ import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import fs from 'fs'; import fs from 'fs';
import WorkboxPlugin from 'workbox-webpack-plugin'; 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 // eslint-disable-next-line @typescript-eslint/no-var-requires
require('dotenv').config(); require('dotenv').config();
@ -45,7 +46,9 @@ const plugins: Configuration['plugins'] = [
'process.env.NODE_ENV': JSON.stringify(NODE_ENV), 'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
'process.env.SERVICE_URL': JSON.stringify(process.env.SERVICE_URL), 'process.env.SERVICE_URL': JSON.stringify(process.env.SERVICE_URL),
'process.env.VERSION': JSON.stringify( 'process.env.VERSION': JSON.stringify(
process.env.VERSION || packageJson.version `${process.env.VERSION || packageJson.version}-${dayjs().format(
'YYYYMMDD'
)}-${getCommitHash()}`
), ),
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({

Loading…
Cancel
Save