chore(projects): use json5 resolve env VITE_OTHER_SERVICE_BASE_URL
& fix proxy enable
This commit is contained in:
parent
26c93dff9a
commit
b16a96323a
@ -5,10 +5,10 @@ import { createServiceConfig } from '../../src/utils/service';
|
|||||||
* Set http proxy
|
* Set http proxy
|
||||||
*
|
*
|
||||||
* @param env - The current env
|
* @param env - The current env
|
||||||
* @param isDev - Is development environment
|
* @param enable - If enable http proxy
|
||||||
*/
|
*/
|
||||||
export function createViteProxy(env: Env.ImportMeta, isDev: boolean) {
|
export function createViteProxy(env: Env.ImportMeta, enable: boolean) {
|
||||||
const isEnableHttpProxy = isDev && env.VITE_HTTP_PROXY === 'Y';
|
const isEnableHttpProxy = enable && env.VITE_HTTP_PROXY === 'Y';
|
||||||
|
|
||||||
if (!isEnableHttpProxy) return undefined;
|
if (!isEnableHttpProxy) return undefined;
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@
|
|||||||
"@vitejs/plugin-vue-jsx": "4.0.0",
|
"@vitejs/plugin-vue-jsx": "4.0.0",
|
||||||
"eslint": "9.8.0",
|
"eslint": "9.8.0",
|
||||||
"eslint-plugin-vue": "9.27.0",
|
"eslint-plugin-vue": "9.27.0",
|
||||||
|
"json5": "2.2.3",
|
||||||
"lint-staged": "15.2.7",
|
"lint-staged": "15.2.7",
|
||||||
"sass": "1.77.8",
|
"sass": "1.77.8",
|
||||||
"simple-git-hooks": "2.11.1",
|
"simple-git-hooks": "2.11.1",
|
||||||
|
@ -117,6 +117,9 @@ importers:
|
|||||||
eslint-plugin-vue:
|
eslint-plugin-vue:
|
||||||
specifier: 9.27.0
|
specifier: 9.27.0
|
||||||
version: 9.27.0(eslint@9.8.0)
|
version: 9.27.0(eslint@9.8.0)
|
||||||
|
json5:
|
||||||
|
specifier: 2.2.3
|
||||||
|
version: 2.2.3
|
||||||
lint-staged:
|
lint-staged:
|
||||||
specifier: 15.2.7
|
specifier: 15.2.7
|
||||||
version: 15.2.7
|
version: 15.2.7
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import json5 from 'json5';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create service config by current env
|
* Create service config by current env
|
||||||
*
|
*
|
||||||
@ -8,10 +10,10 @@ export function createServiceConfig(env: Env.ImportMeta) {
|
|||||||
|
|
||||||
let other = {} as Record<App.Service.OtherBaseURLKey, string>;
|
let other = {} as Record<App.Service.OtherBaseURLKey, string>;
|
||||||
try {
|
try {
|
||||||
other = JSON.parse(VITE_OTHER_SERVICE_BASE_URL);
|
other = json5.parse(VITE_OTHER_SERVICE_BASE_URL);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error('VITE_OTHER_SERVICE_BASE_URL is not a valid JSON string');
|
console.error('VITE_OTHER_SERVICE_BASE_URL is not a valid json5 string');
|
||||||
}
|
}
|
||||||
|
|
||||||
const httpConfig: App.Service.SimpleServiceConfig = {
|
const httpConfig: App.Service.SimpleServiceConfig = {
|
||||||
|
@ -9,6 +9,8 @@ export default defineConfig(configEnv => {
|
|||||||
|
|
||||||
const buildTime = getBuildTime();
|
const buildTime = getBuildTime();
|
||||||
|
|
||||||
|
const enableProxy = configEnv.command === 'serve' && !configEnv.isPreview;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
base: viteEnv.VITE_BASE_URL,
|
base: viteEnv.VITE_BASE_URL,
|
||||||
resolve: {
|
resolve: {
|
||||||
@ -32,7 +34,7 @@ export default defineConfig(configEnv => {
|
|||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: 9527,
|
port: 9527,
|
||||||
open: true,
|
open: true,
|
||||||
proxy: createViteProxy(viteEnv, configEnv.command === 'serve'),
|
proxy: createViteProxy(viteEnv, enableProxy),
|
||||||
fs: {
|
fs: {
|
||||||
cachedChecks: false
|
cachedChecks: false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user