perf(vite.config | view/sidebar): CI/CD 支持 | 构建信息显示
+ 适配Jenkins 持续集成功能。
+ 当版本库中出现新版本将自动构建并部署,以保证服务器版本为最新
+ 侧边栏下显示当前构建版本 和 构建时间
This commit is contained in:
@@ -21,6 +21,10 @@
|
|||||||
/>
|
/>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
|
<div class="sidebar-version">
|
||||||
|
构建版本: {{ commitId }}<br/>
|
||||||
|
<div>构建时间: {{ formatTime(buildTime) }}</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -32,6 +36,21 @@ import useAppStore from '@/store/modules/app'
|
|||||||
import useSettingsStore from '@/store/modules/settings'
|
import useSettingsStore from '@/store/modules/settings'
|
||||||
import usePermissionStore from '@/store/modules/permission'
|
import usePermissionStore from '@/store/modules/permission'
|
||||||
|
|
||||||
|
const buildTime = __BUILD_TIME__
|
||||||
|
const commitId = __COMMIT_ID__
|
||||||
|
const formatTime = (time) => {
|
||||||
|
return new Intl.DateTimeFormat('zh-CN', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: '2-digit',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
hour12: false,
|
||||||
|
timeZone: 'Asia/Shanghai'
|
||||||
|
}).format(new Date(time))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
const settingsStore = useSettingsStore()
|
const settingsStore = useSettingsStore()
|
||||||
@@ -101,4 +120,22 @@ const activeMenu = computed(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.sidebar-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-wrapper {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-version {
|
||||||
|
padding: 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #999;
|
||||||
|
text-align: left;
|
||||||
|
border-top: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,13 +1,27 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import createVitePlugins from './vite/plugins'
|
import createVitePlugins from './vite/plugins'
|
||||||
|
import { execSync } from 'node:child_process'
|
||||||
const baseUrl = 'http://127.0.0.1:8080' // 后端接口
|
const baseUrl = 'http://127.0.0.1:8080' // 后端接口
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig(({ mode, command }) => {
|
export default defineConfig(({ mode, command }) => {
|
||||||
const env = loadEnv(mode, process.cwd())
|
const env = loadEnv(mode, process.cwd())
|
||||||
const { VITE_APP_ENV } = env
|
const { VITE_APP_ENV } = env
|
||||||
|
|
||||||
|
|
||||||
|
let commitId = 'unknown'
|
||||||
|
|
||||||
|
try {
|
||||||
|
commitId = execSync('git rev-parse --short HEAD')
|
||||||
|
.toString()
|
||||||
|
.trim()
|
||||||
|
} catch (e) {
|
||||||
|
console.log('git commit not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildTime = new Date().toISOString()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// 部署生产环境和开发环境下的URL。
|
// 部署生产环境和开发环境下的URL。
|
||||||
// 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
|
// 默认情况下,vite 会假设你的应用是被部署在一个域名的根路径上
|
||||||
@@ -75,6 +89,10 @@ export default defineConfig(({ mode, command }) => {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
define: {
|
||||||
|
__BUILD_TIME__: JSON.stringify(buildTime),
|
||||||
|
__COMMIT_ID__: JSON.stringify(commitId)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user