diff --git a/build/config/proxy.ts b/build/config/proxy.ts index 350dfee9..548ea4e7 100644 --- a/build/config/proxy.ts +++ b/build/config/proxy.ts @@ -5,10 +5,10 @@ import { createServiceConfig } from '../../src/utils/service'; * Set http proxy * * @param env - The current env - * @param isDev - Is development environment + * @param enable - If enable http proxy */ -export function createViteProxy(env: Env.ImportMeta, isDev: boolean) { - const isEnableHttpProxy = isDev && env.VITE_HTTP_PROXY === 'Y'; +export function createViteProxy(env: Env.ImportMeta, enable: boolean) { + const isEnableHttpProxy = enable && env.VITE_HTTP_PROXY === 'Y'; if (!isEnableHttpProxy) return undefined; diff --git a/package.json b/package.json index 1bc13d85..c807a9d7 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "@vitejs/plugin-vue-jsx": "4.0.0", "eslint": "9.8.0", "eslint-plugin-vue": "9.27.0", + "json5": "2.2.3", "lint-staged": "15.2.7", "sass": "1.77.8", "simple-git-hooks": "2.11.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ea21615..f7d8282c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -117,6 +117,9 @@ importers: eslint-plugin-vue: specifier: 9.27.0 version: 9.27.0(eslint@9.8.0) + json5: + specifier: 2.2.3 + version: 2.2.3 lint-staged: specifier: 15.2.7 version: 15.2.7 diff --git a/src/utils/service.ts b/src/utils/service.ts index 5ae09fb7..3586c64b 100644 --- a/src/utils/service.ts +++ b/src/utils/service.ts @@ -1,3 +1,5 @@ +import json5 from 'json5'; + /** * Create service config by current env * @@ -8,10 +10,10 @@ export function createServiceConfig(env: Env.ImportMeta) { let other = {} as Record; try { - other = JSON.parse(VITE_OTHER_SERVICE_BASE_URL); + other = json5.parse(VITE_OTHER_SERVICE_BASE_URL); } catch (error) { // 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 = { diff --git a/vite.config.ts b/vite.config.ts index 218d28c9..dfc20a9b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,6 +9,8 @@ export default defineConfig(configEnv => { const buildTime = getBuildTime(); + const enableProxy = configEnv.command === 'serve' && !configEnv.isPreview; + return { base: viteEnv.VITE_BASE_URL, resolve: { @@ -32,7 +34,7 @@ export default defineConfig(configEnv => { host: '0.0.0.0', port: 9527, open: true, - proxy: createViteProxy(viteEnv, configEnv.command === 'serve'), + proxy: createViteProxy(viteEnv, enableProxy), fs: { cachedChecks: false }