21 lines
592 B
TypeScript
21 lines
592 B
TypeScript
import type { Plugin } from 'vite';
|
|
import { APP_VERSION, APP_NAME } from '../../src/config/version';
|
|
|
|
/**
|
|
* Vite 插件:在 HTML 中注入版本号
|
|
* 替换 HTML 中的占位符为实际版本号
|
|
*/
|
|
export default function versionHtmlPlugin(): Plugin {
|
|
return {
|
|
name: 'vite-plugin-version-html',
|
|
enforce: 'pre',
|
|
transformIndexHtml(html) {
|
|
// 替换 HTML 中的版本占位符
|
|
return html
|
|
.replace(/%APP_NAME%/g, APP_NAME)
|
|
.replace(/%APP_VERSION%/g, APP_VERSION)
|
|
.replace(/%APP_FULL_NAME%/g, `${APP_NAME} ${APP_VERSION}`);
|
|
},
|
|
};
|
|
}
|