html.ts 634 B

12345678910111213141516171819202122232425262728
  1. import { createHtmlPlugin } from 'vite-plugin-html';
  2. import dayjs from 'dayjs';
  3. import { __APP_INFO__ } from '../utils';
  4. const t = dayjs(__APP_INFO__.lastBuildTime).format('YYYYMMDDHHmmss');
  5. const getAppConfigSrc = () => {
  6. return `/admin-config.js?v=${__APP_INFO__.pkg.version}-${t}`;
  7. };
  8. export default function createHtml() {
  9. return createHtmlPlugin({
  10. inject: {
  11. data: {
  12. title: __APP_INFO__.APP_TITLE,
  13. __APP_INFO__: JSON.stringify(__APP_INFO__)
  14. },
  15. tags: [
  16. {
  17. tag: 'script',
  18. attrs: {
  19. src: getAppConfigSrc()
  20. }
  21. }
  22. ]
  23. }
  24. });
  25. }