您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031
  1. import html from 'vite-plugin-html'
  2. import { version } from '../../../package.json'
  3. import { GLOB_CONFIG_FILE_NAME } from '../../constant'
  4. export function configHtmlPlugin(viteEnv, isBuild) {
  5. const { VITE_APP_TITLE, VITE_PUBLIC_PATH } = viteEnv
  6. const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`
  7. const getAppConfigSrc = () => {
  8. return `${path}${GLOB_CONFIG_FILE_NAME}?v=${version}-${new Date().getTime()}`
  9. }
  10. const htmlPlugin = html({
  11. minify: isBuild,
  12. inject: {
  13. data: {
  14. title: VITE_APP_TITLE
  15. },
  16. tags: isBuild
  17. ? [
  18. {
  19. tag: 'script',
  20. attrs: {
  21. src: getAppConfigSrc()
  22. }
  23. }
  24. ]
  25. : []
  26. }
  27. })
  28. return htmlPlugin
  29. }