Blame view

build/vite/plugin/html.ts 832 Bytes
1
import type { Plugin } from 'vite';
vben authored
2
3
import html from 'vite-plugin-html';
import { ViteEnv } from '../../utils';
4
5
6
7
8

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