html.ts 832 B

1234567891011121314151617181920212223242526272829303132
  1. import type { Plugin } from 'vite';
  2. import html from 'vite-plugin-html';
  3. import { ViteEnv } from '../../utils';
  4. // @ts-ignore
  5. import pkg from '../../../package.json';
  6. import { GLOB_CONFIG_FILE_NAME } from '../../constant';
  7. export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
  8. const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
  9. const htmlPlugin: Plugin[] = html({
  10. minify: isBuild,
  11. inject: {
  12. injectData: {
  13. title: VITE_GLOB_APP_TITLE,
  14. },
  15. tags: isBuild
  16. ? [
  17. {
  18. tag: 'script',
  19. attrs: {
  20. src: `${VITE_PUBLIC_PATH || './'}${GLOB_CONFIG_FILE_NAME}?v=${
  21. pkg.version
  22. }-${new Date().getTime()}`,
  23. },
  24. },
  25. ]
  26. : [],
  27. },
  28. });
  29. return htmlPlugin;
  30. }