UNPKG

create-iking-admin

Version:

金合技术中台脚手架

49 lines (44 loc) 1.28 kB
/* * @Author: wfl * @LastEditors: wfl * @description: * @updateInfo: * @Date: 2022-08-12 18:42:51 * @LastEditTime: 2022-08-24 18:08:18 */ /** * Plugin to minimize and use ejs template syntax in index.html. * https://github.com/anncwb/vite-plugin-html */ import type { Plugin } from 'vite'; import html from 'vite-plugin-html'; import pkg from '../../../package.json'; import { GLOB_CONFIG_FILE_NAME } from '../../constant'; export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env; const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`; const getAppConfigSrc = () => { return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`; }; const htmlPlugin: Plugin[] = html({ minify: isBuild, inject: { // Inject data into ejs template data: { title: VITE_GLOB_APP_TITLE, }, // Embed the generated app.config.js file tags: isBuild ? [ { tag: 'script', attrs: { src: getAppConfigSrc(), }, }, ] : [], }, }); return htmlPlugin; }