vben-admin-thin-next/build/vite/plugin/html.ts

35 lines
911 B
TypeScript
Raw Normal View History

import type { Plugin } from 'vite';
2021-01-09 23:28:52 +08:00
import html from 'vite-plugin-html';
import { ViteEnv } from '../../utils';
// @ts-ignore
import pkg from '../../../package.json';
import { GLOB_CONFIG_FILE_NAME } from '../../constant';
2021-01-09 23:28:52 +08:00
export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
2021-01-12 06:12:13 +08:00
const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`;
2021-01-09 23:28:52 +08:00
const htmlPlugin: Plugin[] = html({
minify: isBuild,
inject: {
injectData: {
title: VITE_GLOB_APP_TITLE,
},
tags: isBuild
? [
{
tag: 'script',
attrs: {
2021-01-12 06:12:13 +08:00
src: `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${
2021-01-09 23:28:52 +08:00
pkg.version
}-${new Date().getTime()}`,
},
},
]
: [],
},
});
2021-01-09 23:28:52 +08:00
return htmlPlugin;
}