Skip to content

Commit b16a963

Browse files
committed
chore(projects): use json5 resolve env VITE_OTHER_SERVICE_BASE_URL & fix proxy enable
1 parent 26c93df commit b16a963

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

build/config/proxy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { createServiceConfig } from '../../src/utils/service';
55
* Set http proxy
66
*
77
* @param env - The current env
8-
* @param isDev - Is development environment
8+
* @param enable - If enable http proxy
99
*/
10-
export function createViteProxy(env: Env.ImportMeta, isDev: boolean) {
11-
const isEnableHttpProxy = isDev && env.VITE_HTTP_PROXY === 'Y';
10+
export function createViteProxy(env: Env.ImportMeta, enable: boolean) {
11+
const isEnableHttpProxy = enable && env.VITE_HTTP_PROXY === 'Y';
1212

1313
if (!isEnableHttpProxy) return undefined;
1414

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"@vitejs/plugin-vue-jsx": "4.0.0",
8686
"eslint": "9.8.0",
8787
"eslint-plugin-vue": "9.27.0",
88+
"json5": "2.2.3",
8889
"lint-staged": "15.2.7",
8990
"sass": "1.77.8",
9091
"simple-git-hooks": "2.11.1",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json5 from 'json5';
2+
13
/**
24
* Create service config by current env
35
*
@@ -8,10 +10,10 @@ export function createServiceConfig(env: Env.ImportMeta) {
810

911
let other = {} as Record<App.Service.OtherBaseURLKey, string>;
1012
try {
11-
other = JSON.parse(VITE_OTHER_SERVICE_BASE_URL);
13+
other = json5.parse(VITE_OTHER_SERVICE_BASE_URL);
1214
} catch (error) {
1315
// eslint-disable-next-line no-console
14-
console.error('VITE_OTHER_SERVICE_BASE_URL is not a valid JSON string');
16+
console.error('VITE_OTHER_SERVICE_BASE_URL is not a valid json5 string');
1517
}
1618

1719
const httpConfig: App.Service.SimpleServiceConfig = {

vite.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export default defineConfig(configEnv => {
99

1010
const buildTime = getBuildTime();
1111

12+
const enableProxy = configEnv.command === 'serve' && !configEnv.isPreview;
13+
1214
return {
1315
base: viteEnv.VITE_BASE_URL,
1416
resolve: {
@@ -32,7 +34,7 @@ export default defineConfig(configEnv => {
3234
host: '0.0.0.0',
3335
port: 9527,
3436
open: true,
35-
proxy: createViteProxy(viteEnv, configEnv.command === 'serve'),
37+
proxy: createViteProxy(viteEnv, enableProxy),
3638
fs: {
3739
cachedChecks: false
3840
}

0 commit comments

Comments
 (0)