diff --git a/.env b/.env index fe8b10e..6d4a853 100644 --- a/.env +++ b/.env @@ -1,2 +1,5 @@ # 项目根目录 -VITE_BASE_URL=/ \ No newline at end of file +VITE_BASE_URL=/ + +# 项目名称 +VITE_APP_TITLE = 'Ench Admin' \ No newline at end of file diff --git a/build/config/proxy.ts b/build/config/proxy.ts index 6b35dee..4a31c7b 100644 --- a/build/config/proxy.ts +++ b/build/config/proxy.ts @@ -25,14 +25,14 @@ const serviceEnv = { /** * @description: 生成vite代理字段 - * @param {*} viteEnv - 环境变量配置 + * @param {*} env - 环境变量配置 */ -export function createViteProxy(viteEnv) { +export function createViteProxy(env) { //判断是否需要开启代理 - const isOpenProxy = viteEnv.VITE_HTTP_PROXY === 'Y'; + const isOpenProxy = env.VITE_HTTP_PROXY === 'Y'; if (!isOpenProxy) return undefined; // 返回对应代理 - const { VITE_SERVICE_ENV = 'dev' } = viteEnv; + const { VITE_SERVICE_ENV = 'dev' } = env; return serviceEnv[VITE_SERVICE_ENV]; } diff --git a/build/plugins/compress.ts b/build/plugins/compress.ts index 678cfc7..9d0b33d 100644 --- a/build/plugins/compress.ts +++ b/build/plugins/compress.ts @@ -1,9 +1,8 @@ import viteCompression from 'vite-plugin-compression'; //https://github.com/vbenjs/vite-plugin-compression/blob/main/README.zh_CN.md -export default (viteEnv) => { +export default (env) => { // 默认使用gzip压缩 - const { VITE_COMPRESS_TYPE = 'gzip' } = viteEnv; - + const { VITE_COMPRESS_TYPE = 'gzip' } = env; return viteCompression({ algorithm: VITE_COMPRESS_TYPE, // 压缩算法 }); diff --git a/build/plugins/html.ts b/build/plugins/html.ts new file mode 100644 index 0000000..db3f5b1 --- /dev/null +++ b/build/plugins/html.ts @@ -0,0 +1,13 @@ +import { createHtmlPlugin } from 'vite-plugin-html'; // https://github.com/vbenjs/vite-plugin-html/blob/main/README.zh_CN.md + +export default (env) => { + return createHtmlPlugin({ + minify: true, // 压缩HTML + inject: { + // 注入数据 + data: { + title: env.VITE_APP_TITLE, + }, + }, + }); +}; diff --git a/build/plugins/index.ts b/build/plugins/index.ts index e3639d5..be86f6a 100644 --- a/build/plugins/index.ts +++ b/build/plugins/index.ts @@ -1,16 +1,17 @@ import vue from './vue'; import compress from './compress'; +import html from './html'; /** * @description: 设置vite插件配置 - * @param {*} viteEnv - 环境变量配置 + * @param {*} env - 环境变量配置 * @return {*} */ -export function setVitePlugins(viteEnv) { - const plugins = [...vue]; +export function setVitePlugins(env) { + const plugins = [...vue, html(env)]; - if (viteEnv.VITE_COMPRESS_OPEN === 'Y') { - plugins.push(compress(viteEnv)); + if (env.VITE_COMPRESS_OPEN === 'Y') { + plugins.push(compress(env)); } return plugins; diff --git a/index.html b/index.html index fb37072..ec34ff3 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ -