fix: 使用环境变量动态设置页面标题

在index.html中使用%VITE_APP_TITLE%占位符替换硬编码的标题
修改vite.config.ts以在构建时将占位符替换为环境变量中的实际值
This commit is contained in:
feige996
2025-09-02 10:32:48 +08:00
parent 02b2c00acd
commit b0a77baa7d
2 changed files with 2 additions and 2 deletions

View File

@@ -14,7 +14,7 @@
'" />', '" />',
) )
</script> </script>
<title>unibest</title> <title>%VITE_APP_TITLE%</title>
<!--preload-links--> <!--preload-links-->
<!--app-context--> <!--app-context-->
</head> </head>

View File

@@ -111,7 +111,7 @@ export default ({ command, mode }) => {
UNI_PLATFORM === 'h5' && { UNI_PLATFORM === 'h5' && {
name: 'html-transform', name: 'html-transform',
transformIndexHtml(html) { transformIndexHtml(html) {
return html.replace('%BUILD_TIME%', dayjs().format('YYYY-MM-DD HH:mm:ss')) return html.replace('%BUILD_TIME%', dayjs().format('YYYY-MM-DD HH:mm:ss')).replace('%VITE_APP_TITLE%', env.VITE_APP_TITLE)
}, },
}, },
// 打包分析插件h5 + 生产环境才弹出 // 打包分析插件h5 + 生产环境才弹出