From a59d608f09a1c777c55c73fe61e6fdcfc4e047fd Mon Sep 17 00:00:00 2001 From: mrcuix Date: Mon, 25 Jul 2022 19:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8E=20ci(=E7=89=88=E6=9C=AC=E5=8F=B7):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 构建版本号/分支信息 --- config/dev.js | 3 +++ config/index.js | 9 +++++++++ config/prod.js | 27 ++++++++++++++++++++++++++- src/pages/user/index.tsx | 8 +++++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/config/dev.js b/config/dev.js index 849d3af..ae97f48 100644 --- a/config/dev.js +++ b/config/dev.js @@ -17,6 +17,9 @@ module.exports = { args: [{ terserOptions: { compress: true, // 默认使用terser压缩 + // compress: { + // drop_console: true, // 去掉打印 + // }, // 默认使用terser压缩 // mangle: false, keep_classnames: true, // 不改变class名称 keep_fnames: true // 不改变函数名称 diff --git a/config/index.js b/config/index.js index d68f13d..62c89fe 100644 --- a/config/index.js +++ b/config/index.js @@ -1,3 +1,10 @@ +const path = require('path') +const childProcess = require('child_process'); +const versions = childProcess.execSync('git rev-parse --abbrev-ref HEAD', { 'encoding': 'utf8' }) != "HEAD\n" ? childProcess.execSync('git rev-parse --abbrev-ref HEAD', { 'encoding': 'utf8' }) : childProcess.execSync('git describe --tags --abbrev=0', { 'encoding': 'utf8' }) +const CURRENT_GITHASH = childProcess.execSync('git rev-parse --short HEAD', { 'encoding': 'utf8' }) +const CURRENT_VERSION = `Version: ${JSON.stringify(process.env.CODE_BRANCH || versions)} ${CURRENT_GITHASH} ${new Date().toLocaleString()}`.replace(/\"|\\n/g, ''); + + const config = { projectName: 'EShop', date: '2022-4-6', @@ -11,6 +18,8 @@ const config = { outputRoot: 'dist', plugins: [], defineConstants: { + CURRENT_VERSION: JSON.stringify(CURRENT_VERSION), + CURRENT_GITHASH: JSON.stringify(CURRENT_GITHASH), CURRENT_ENV: JSON.stringify(process.env.NODE_ENV) }, copy: { diff --git a/config/prod.js b/config/prod.js index 30ccf79..8b30be6 100644 --- a/config/prod.js +++ b/config/prod.js @@ -5,7 +5,32 @@ module.exports = { }, defineConstants: { }, - mini: {}, + mini: { + optimizeMainPackage: { + enable: true + }, + webpackChain: (chain, webpack) => { + chain.merge({ + plugin: { + install: { + plugin: require('terser-webpack-plugin'), + args: [{ + terserOptions: { + // compress: true, // 默认使用terser压缩 + compress: { + drop_console: true, // 去掉打印 + }, // 默认使用terser压缩 + // mangle: false, + keep_classnames: true, // 不改变class名称 + keep_fnames: true // 不改变函数名称 + } + }] + } + } + }) + } + + }, h5: { /** * 如果h5端编译后体积过大,可以使用webpack-bundle-analyzer插件对打包体积进行分析。 diff --git a/src/pages/user/index.tsx b/src/pages/user/index.tsx index 03593f8..1b1dd10 100644 --- a/src/pages/user/index.tsx +++ b/src/pages/user/index.tsx @@ -18,6 +18,11 @@ export default () => { // 用户信息 const { getSelfUserInfo, getAdminUserInfo } = useLogin(); const { adminUserInfo } = useSelector(state => state.userInfo); + + const [current_version,setCurrent_version] = useState(CURRENT_VERSION) + const [current_githash,setCurrent_githash] = useState(CURRENT_GITHASH) + const [current_env,setCurrent_env] = useState(CURRENT_ENV) + useEffect(() => { // getSelfUserInfo().then().catch(() => { // alert.none("授权失败,请授权后再使用"); @@ -65,7 +70,8 @@ export default () => {
{/* {(adminUserInfo as any)?.authentication_status==1&&} */} {/* 测试暂时添加 */} - {BASE_URL} + {current_version} + {current_env === 'development' &&{BASE_URL}} {!adminUserInfo?.is_authorize_name && } )