You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 line
786B

  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. }