chore(designer): 增加环境变量配置
This commit is contained in:
parent
e758bc3692
commit
faa23bec88
8
apps/designer/.env
Normal file
8
apps/designer/.env
Normal file
@ -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 = ''
|
10
apps/designer/.env.development
Normal file
10
apps/designer/.env.development
Normal file
@ -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
|
7
apps/designer/.env.production
Normal file
7
apps/designer/.env.production
Normal file
@ -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/'
|
8
apps/designer/.env.staging
Normal file
8
apps/designer/.env.staging
Normal file
@ -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/'
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,12 +6,9 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"setup": "npm install --unsafe-perm --registry=https://registry.npmmirror.com",
|
"setup": "npm install --unsafe-perm --registry=https://registry.npmmirror.com",
|
||||||
"dev": "cross-env ENV_TYPE=local vite",
|
"dev": "cross-env vite --mode development",
|
||||||
"build": "npm run build:prod",
|
"build": "vite build --mode production",
|
||||||
"build:sit": "vue-tsc && cross-env ENV_TYPE=sit vite build",
|
"build:staging": "vite build --mode staging",
|
||||||
"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",
|
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"clean": "rimraf node_modules"
|
"clean": "rimraf node_modules"
|
||||||
},
|
},
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import axios from 'axios';
|
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({
|
const instance = axios.create({
|
||||||
baseURL: baseApiUrl // 基础URL直接放在实例配置中
|
baseURL: apiBase // 基础URL直接放在实例配置中
|
||||||
});
|
});
|
||||||
|
|
||||||
// 请求拦截器改为使用实例
|
// 请求拦截器改为使用实例
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig, loadEnv } from 'vite';
|
||||||
import { createViteConfig } from '@vtj/cli';
|
import { createViteConfig } from '@vtj/cli';
|
||||||
import { createDevTools } from '@vtj/local';
|
import { createDevTools } from '@vtj/local';
|
||||||
import http2Proxy from '@sy/vite-plugin-http2-proxy';
|
import http2Proxy from '@sy/vite-plugin-http2-proxy';
|
||||||
// import proxy from './proxy.config';
|
|
||||||
import mkcert from 'vite-plugin-mkcert';
|
import mkcert from 'vite-plugin-mkcert';
|
||||||
import AutoImport from 'unplugin-auto-import/vite';
|
import AutoImport from 'unplugin-auto-import/vite';
|
||||||
|
|
||||||
@ -31,11 +30,21 @@ const config = createViteConfig({
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
export default defineConfig({
|
// @ts-ignore
|
||||||
...config,
|
export default defineConfig(({ mode }) => {
|
||||||
server: {
|
console.log('mode', mode);
|
||||||
https: true,
|
// 加载环境变量(支持 .env.development/.env.production)
|
||||||
port: 10011,
|
const env = loadEnv(mode, process.cwd(), ['VITE_', 'VTJ_', 'SY_']);
|
||||||
host: true
|
return {
|
||||||
}
|
...config,
|
||||||
|
server: {
|
||||||
|
https: true,
|
||||||
|
port: env.VITE_PORT,
|
||||||
|
host: true
|
||||||
|
},
|
||||||
|
define: {
|
||||||
|
// 注入环境变量到客户端
|
||||||
|
__APP_ENV__: JSON.stringify(env)
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
8
apps/renderer/.env.development
Normal file
8
apps/renderer/.env.development
Normal file
@ -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/'
|
7
apps/renderer/.env.production
Normal file
7
apps/renderer/.env.production
Normal file
@ -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/'
|
Loading…
x
Reference in New Issue
Block a user