mirror of
				https://github.com/soybeanjs/soybean-admin.git
				synced 2025-11-04 07:43:42 +08:00 
			
		
		
		
	chore(projects): use json5 resolve env VITE_OTHER_SERVICE_BASE_URL & fix proxy enable
				
					
				
			This commit is contained in:
		@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										3
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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<App.Service.OtherBaseURLKey, string>;
 | 
			
		||||
  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 = {
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user