From faa23bec88fcab3fc7fde2b6f71e1c9a837a7f19 Mon Sep 17 00:00:00 2001 From: wangxuefeng Date: Mon, 3 Mar 2025 17:07:36 +0800 Subject: [PATCH] =?UTF-8?q?chore(designer):=20=E5=A2=9E=E5=8A=A0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/designer/.env | 8 +++ apps/designer/.env.development | 10 +++ apps/designer/.env.production | 7 ++ apps/designer/.env.staging | 8 +++ apps/designer/.eslintrc-auto-import.json | 91 ------------------------ apps/designer/package.json | 9 +-- apps/designer/src/io/instance.ts | 5 +- apps/designer/vite.config.ts | 27 ++++--- apps/renderer/.env.development | 8 +++ apps/renderer/.env.production | 7 ++ 10 files changed, 72 insertions(+), 108 deletions(-) create mode 100644 apps/designer/.env create mode 100644 apps/designer/.env.development create mode 100644 apps/designer/.env.production create mode 100644 apps/designer/.env.staging delete mode 100644 apps/designer/.eslintrc-auto-import.json create mode 100644 apps/renderer/.env.development create mode 100644 apps/renderer/.env.production diff --git a/apps/designer/.env b/apps/designer/.env new file mode 100644 index 0000000..eb5171e --- /dev/null +++ b/apps/designer/.env @@ -0,0 +1,8 @@ +# 通用环境配置 +ENV = 'development' + +# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path +VITE_BASE_URL = / + +# base api url +VITE_BASE_API_URL = '' \ No newline at end of file diff --git a/apps/designer/.env.development b/apps/designer/.env.development new file mode 100644 index 0000000..bb4a0c8 --- /dev/null +++ b/apps/designer/.env.development @@ -0,0 +1,10 @@ +# 只在开发模式中被载入 +ENV = 'development' + +# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path +VITE_BASE_URL = / + +# 前端可见变量(必须以 VITE_ 开头) +VITE_PORT = 10011 +VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' +VITE_DEBUG_MODE = true \ No newline at end of file diff --git a/apps/designer/.env.production b/apps/designer/.env.production new file mode 100644 index 0000000..fdb49f4 --- /dev/null +++ b/apps/designer/.env.production @@ -0,0 +1,7 @@ +# 只在生产模式中被载入 +ENV = 'production' + +# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path +VITE_BASE_URL = / + +VITE_BASE_API_URL = 'https://custom-chart-api.shiyuegame.com/' diff --git a/apps/designer/.env.staging b/apps/designer/.env.staging new file mode 100644 index 0000000..7582267 --- /dev/null +++ b/apps/designer/.env.staging @@ -0,0 +1,8 @@ +# 只在预发布模式中被载入 +ENV = 'staging' + +# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path +VITE_BASE_URL = / + +# base api url +VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' \ No newline at end of file diff --git a/apps/designer/.eslintrc-auto-import.json b/apps/designer/.eslintrc-auto-import.json deleted file mode 100644 index 181d852..0000000 --- a/apps/designer/.eslintrc-auto-import.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "globals": { - "Component": true, - "ComponentPublicInstance": true, - "ComputedRef": true, - "DirectiveBinding": true, - "EffectScope": true, - "ExtractDefaultPropTypes": true, - "ExtractPropTypes": true, - "ExtractPublicPropTypes": true, - "InjectionKey": true, - "MaybeRef": true, - "MaybeRefOrGetter": true, - "PropType": true, - "Ref": true, - "VNode": true, - "WritableComputedRef": true, - "acceptHMRUpdate": true, - "computed": true, - "createApp": true, - "createPinia": true, - "customRef": true, - "defineAsyncComponent": true, - "defineComponent": true, - "defineStore": true, - "effectScope": true, - "getActivePinia": true, - "getCurrentInstance": true, - "getCurrentScope": true, - "h": true, - "inject": true, - "isProxy": true, - "isReactive": true, - "isReadonly": true, - "isRef": true, - "mapActions": true, - "mapGetters": true, - "mapState": true, - "mapStores": true, - "mapWritableState": true, - "markRaw": true, - "nextTick": true, - "onActivated": true, - "onBeforeMount": true, - "onBeforeRouteLeave": true, - "onBeforeRouteUpdate": true, - "onBeforeUnmount": true, - "onBeforeUpdate": true, - "onDeactivated": true, - "onErrorCaptured": true, - "onMounted": true, - "onRenderTracked": true, - "onRenderTriggered": true, - "onScopeDispose": true, - "onServerPrefetch": true, - "onUnmounted": true, - "onUpdated": true, - "onWatcherCleanup": true, - "provide": true, - "reactive": true, - "readonly": true, - "ref": true, - "resolveComponent": true, - "setActivePinia": true, - "setMapStoreSuffix": true, - "shallowReactive": true, - "shallowReadonly": true, - "shallowRef": true, - "storeToRefs": true, - "toRaw": true, - "toRef": true, - "toRefs": true, - "toValue": true, - "triggerRef": true, - "unref": true, - "useAttrs": true, - "useCssModule": true, - "useCssVars": true, - "useId": true, - "useLink": true, - "useModel": true, - "useRoute": true, - "useRouter": true, - "useSlots": true, - "useTemplateRef": true, - "watch": true, - "watchEffect": true, - "watchPostEffect": true, - "watchSyncEffect": true - } -} diff --git a/apps/designer/package.json b/apps/designer/package.json index 0ea7e9c..4643a1f 100644 --- a/apps/designer/package.json +++ b/apps/designer/package.json @@ -6,12 +6,9 @@ "type": "module", "scripts": { "setup": "npm install --unsafe-perm --registry=https://registry.npmmirror.com", - "dev": "cross-env ENV_TYPE=local vite", - "build": "npm run build:prod", - "build:sit": "vue-tsc && cross-env ENV_TYPE=sit vite build", - "build:uat": "vue-tsc && cross-env ENV_TYPE=uat vite build", - "build:pre": "vue-tsc && cross-env ENV_TYPE=pre vite build", - "build:prod": "vue-tsc && cross-env ENV_TYPE=live vite build", + "dev": "cross-env vite --mode development", + "build": "vite build --mode production", + "build:staging": "vite build --mode staging", "preview": "vite preview", "clean": "rimraf node_modules" }, diff --git a/apps/designer/src/io/instance.ts b/apps/designer/src/io/instance.ts index 10285a9..bb8710e 100644 --- a/apps/designer/src/io/instance.ts +++ b/apps/designer/src/io/instance.ts @@ -1,10 +1,11 @@ import axios from 'axios'; -const baseApiUrl = 'https://custom-chart-pre-api.shiyue.com/'; +const apiBase = import.meta.env.VITE_BASE_API_URL; +console.log('apiBase', apiBase); // 创建独立实例 const instance = axios.create({ - baseURL: baseApiUrl // 基础URL直接放在实例配置中 + baseURL: apiBase // 基础URL直接放在实例配置中 }); // 请求拦截器改为使用实例 diff --git a/apps/designer/vite.config.ts b/apps/designer/vite.config.ts index dc43a93..35d3a53 100644 --- a/apps/designer/vite.config.ts +++ b/apps/designer/vite.config.ts @@ -1,8 +1,7 @@ -import { defineConfig } from 'vite'; +import { defineConfig, loadEnv } from 'vite'; import { createViteConfig } from '@vtj/cli'; import { createDevTools } from '@vtj/local'; import http2Proxy from '@sy/vite-plugin-http2-proxy'; -// import proxy from './proxy.config'; import mkcert from 'vite-plugin-mkcert'; import AutoImport from 'unplugin-auto-import/vite'; @@ -31,11 +30,21 @@ const config = createViteConfig({ ] }); -export default defineConfig({ - ...config, - server: { - https: true, - port: 10011, - host: true - } +// @ts-ignore +export default defineConfig(({ mode }) => { + console.log('mode', mode); + // 加载环境变量(支持 .env.development/.env.production) + const env = loadEnv(mode, process.cwd(), ['VITE_', 'VTJ_', 'SY_']); + return { + ...config, + server: { + https: true, + port: env.VITE_PORT, + host: true + }, + define: { + // 注入环境变量到客户端 + __APP_ENV__: JSON.stringify(env) + } + }; }); diff --git a/apps/renderer/.env.development b/apps/renderer/.env.development new file mode 100644 index 0000000..c440086 --- /dev/null +++ b/apps/renderer/.env.development @@ -0,0 +1,8 @@ +# 只在开发模式中被载入 +ENV = 'development' + +# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path +VITE_BASE_URL = / + +# base api url +VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/' \ No newline at end of file diff --git a/apps/renderer/.env.production b/apps/renderer/.env.production new file mode 100644 index 0000000..fdb49f4 --- /dev/null +++ b/apps/renderer/.env.production @@ -0,0 +1,7 @@ +# 只在生产模式中被载入 +ENV = 'production' + +# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path +VITE_BASE_URL = / + +VITE_BASE_API_URL = 'https://custom-chart-api.shiyuegame.com/'