From 2f7e871d3d0c78236a3e62037700f2003aa70ca1 Mon Sep 17 00:00:00 2001 From: Coffee-crocodile <1147347984@qq.com> Date: Fri, 2 Jun 2023 16:37:12 +0800 Subject: [PATCH] fix: modify env var to string --- .env.development | 4 +--- .env.production | 7 ++----- build/plugins/index.ts | 6 +++--- build/plugins/unplugin.ts | 2 ++ build/plugins/visualizer.ts | 3 ++- src/service/http/index.ts | 2 +- src/typings/env.d.ts | 8 +++----- vite.config.ts | 2 +- 8 files changed, 15 insertions(+), 19 deletions(-) diff --git a/.env.development b/.env.development index ff4f3df..c32edbc 100644 --- a/.env.development +++ b/.env.development @@ -1,3 +1 @@ -VITE_HTTP_PROXY=false -# 开启localStorage内容加密 -VITE_STORAGE_ENCRYPT=false \ No newline at end of file +VITE_HTTP_PROXY=N diff --git a/.env.production b/.env.production index 95d1bc7..98dff9b 100644 --- a/.env.production +++ b/.env.production @@ -1,11 +1,8 @@ # 是否开启压缩资源 -VITE_COMPRESS_OPEN=false +VITE_COMPRESS_OPEN=N # 压缩算法 gzip | brotliCompress | deflate | deflateRaw VITE_COMPRESS_TYPE=gzip # 是否开启打包依赖分析 -VITE_VISUALIZER=false - -# 开启localStorage内容加密 -VITE_STORAGE_ENCRYPT=false +VITE_VISUALIZER=N diff --git a/build/plugins/index.ts b/build/plugins/index.ts index bd949be..e5dba6f 100644 --- a/build/plugins/index.ts +++ b/build/plugins/index.ts @@ -13,13 +13,13 @@ import mock from './mock' * @return {*} */ export function setVitePlugins(env: ImportMetaEnv) { - const plugins = [...vue, unocss(), ...unplugin, mock, vueSetupExtend()] + const plugins: PluginOption[] = [...vue, unocss(), ...unplugin, mock, vueSetupExtend()] // 是否压缩 - if (env.VITE_COMPRESS_OPEN) + if (env.VITE_COMPRESS_OPEN === 'Y') plugins.push(compress(env)) // 是否依赖分析 - if (env.VITE_VISUALIZER) + if (env.VITE_VISUALIZER === 'Y') plugins.push(visualizer as PluginOption) return plugins diff --git a/build/plugins/unplugin.ts b/build/plugins/unplugin.ts index 2dc998a..418952e 100644 --- a/build/plugins/unplugin.ts +++ b/build/plugins/unplugin.ts @@ -1,8 +1,10 @@ import path from 'node:path' import Components from 'unplugin-vue-components/vite' import { NaiveUiResolver } from 'unplugin-vue-components/resolvers' + import Icons from 'unplugin-icons/vite' // https://github.com/antfu/unplugin-icons import IconsResolver from 'unplugin-icons/resolver' + import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // https://github.com/vbenjs/vite-plugin-svg-icons/blob/main/README.zh_CN.md export default [ diff --git a/build/plugins/visualizer.ts b/build/plugins/visualizer.ts index b606ad8..9f7a117 100644 --- a/build/plugins/visualizer.ts +++ b/build/plugins/visualizer.ts @@ -1,4 +1,5 @@ -import { visualizer } from 'rollup-plugin-visualizer' // https://github.com/btd/rollup-plugin-visualizer +import { visualizer } from 'rollup-plugin-visualizer'// https://github.com/btd/rollup-plugin-visualizer + export default visualizer({ gzipSize: true, brotliSize: true, diff --git a/src/service/http/index.ts b/src/service/http/index.ts index 9fd0c24..bd8402f 100644 --- a/src/service/http/index.ts +++ b/src/service/http/index.ts @@ -3,7 +3,7 @@ import { proxyConfig } from '@/config' const { url, urlPattern } = proxyConfig[import.meta.env.MODE] -const isHttpProxy = import.meta.env.VITE_HTTP_PROXY || false +const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === 'Y' || false export const request = createRequest({ baseURL: isHttpProxy ? urlPattern : url }) diff --git a/src/typings/env.d.ts b/src/typings/env.d.ts index 2cc36e2..8710ef8 100644 --- a/src/typings/env.d.ts +++ b/src/typings/env.d.ts @@ -25,19 +25,17 @@ interface ImportMetaEnv { readonly VITE_APP_TITLE: string; readonly VITE_APP_DESC: string; /** 开启请求代理 */ - readonly VITE_HTTP_PROXY?: boolean; + readonly VITE_HTTP_PROXY?: 'Y'|'N'; /** 是否开启打包依赖分析 */ - readonly VITE_VISUALIZER?: boolean; + readonly VITE_VISUALIZER?: 'Y'|'N'; /** 是否开启打包压缩 */ - readonly VITE_COMPRESS_OPEN?: boolean; + readonly VITE_COMPRESS_OPEN?: 'Y'|'N'; /** 压缩算法类型 */ readonly VITE_COMPRESS_TYPE?: 'gzip' | 'brotliCompress' | 'deflate' | 'deflateRaw'; /** hash路由模式 */ readonly VITE_ROUTE_MODE?: 'hash' | 'web'; /** 路由加载模式 */ readonly VITE_AUTH_ROUTE_MODE?: 'static' | 'dynamic'; - /** 本地存储内容开启加密 */ - readonly VITE_STORAGE_ENCRYPT?: boolean; /** 后端服务的环境类型 */ readonly MODE: ServiceEnvType; diff --git a/vite.config.ts b/vite.config.ts index 4dc1e33..56b1cbf 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -30,7 +30,7 @@ export default defineConfig(({ mode }: ConfigEnv) => { host: '0.0.0.0', port: 3000, open: false, - proxy: env.VITE_HTTP_PROXY ? createViteProxy(envConfig) : undefined, + proxy: env.VITE_HTTP_PROXY === 'Y' ? createViteProxy(envConfig) : undefined, }, preview: { port: 5211,