fix: modify env var to string

This commit is contained in:
Coffee-crocodile 2023-06-02 16:37:12 +08:00
parent adb1e5554c
commit 2f7e871d3d
8 changed files with 15 additions and 19 deletions

View File

@ -1,3 +1 @@
VITE_HTTP_PROXY=false
# 开启localStorage内容加密
VITE_STORAGE_ENCRYPT=false
VITE_HTTP_PROXY=N

View File

@ -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

View File

@ -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

View File

@ -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 [

View File

@ -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,

View File

@ -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 })

View File

@ -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;

View File

@ -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,