'admin-20.12.21:处理打包字体图标404问题'
This commit is contained in:
		
							parent
							
								
									873bb13242
								
							
						
					
					
						commit
						0fa35d56aa
					
				
							
								
								
									
										2
									
								
								vue-admin-wonderful-next/.env.development
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								vue-admin-wonderful-next/.env.development
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | # public path | ||||||
|  | VITE_PUBLIC_PATH = 'vue-admin-wonderful-next-preview' | ||||||
							
								
								
									
										2
									
								
								vue-admin-wonderful-next/.env.production
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								vue-admin-wonderful-next/.env.production
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | |||||||
|  | # public path | ||||||
|  | VITE_PUBLIC_PATH = '' | ||||||
							
								
								
									
										31
									
								
								vue-admin-wonderful-next/build/utils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								vue-admin-wonderful-next/build/utils.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | |||||||
|  | import dotenv from 'dotenv'; | ||||||
|  | 
 | ||||||
|  | export interface ViteEnv { | ||||||
|  |     VITE_PORT: number; | ||||||
|  |     VITE_OPEN: boolean; | ||||||
|  |     VITE_PUBLIC_PATH: string; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export function loadEnv(): ViteEnv { | ||||||
|  |     const env = process.env.NODE_ENV; | ||||||
|  |     const ret: any = {}; | ||||||
|  |     const envList = [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env', ,] | ||||||
|  |     envList.forEach((e) => { | ||||||
|  |         dotenv.config({ | ||||||
|  |             path: e, | ||||||
|  |         }); | ||||||
|  |     }); | ||||||
|  |     for (const envName of Object.keys(process.env)) { | ||||||
|  |         let realName = (process.env as any)[envName].replace(/\\n/g, '\n'); | ||||||
|  |         realName = realName === 'true' ? true : realName === 'false' ? false : realName; | ||||||
|  |         if (envName === 'VITE_PORT') { | ||||||
|  |             realName = Number(realName); | ||||||
|  |         } | ||||||
|  |         if (envName === 'VITE_OPEN') { | ||||||
|  |             realName = Boolean(realName); | ||||||
|  |         } | ||||||
|  |         ret[envName] = realName; | ||||||
|  |         process.env[envName] = realName; | ||||||
|  |     } | ||||||
|  |     return ret; | ||||||
|  | } | ||||||
| @ -1,15 +1,27 @@ | |||||||
| import type { UserConfig } from 'vite'; | import type { UserConfig } from 'vite' | ||||||
| import path from 'path'; | import { resolve } from 'path' | ||||||
|  | import { loadEnv } from './build/utils' | ||||||
|  | 
 | ||||||
|  | const pathResolve = (dir: string): any => { | ||||||
|  |     return resolve(__dirname, '.', dir) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const alias: Record<string, string> = { | ||||||
|  |     '/@/': pathResolve('src'), | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const { VITE_PORT, VITE_PUBLIC_PATH, VITE_OPEN } = loadEnv() | ||||||
|  | 
 | ||||||
|  | const root: string = process.cwd() | ||||||
| 
 | 
 | ||||||
| const viteConfig: UserConfig = { | const viteConfig: UserConfig = { | ||||||
|     sourcemap: false, |     root, | ||||||
|     base: '../', |     alias, | ||||||
|     port: 8080, |     outDir: 'dist', | ||||||
|     hostname: 'localhost', |     minify: 'esbuild', | ||||||
|     open: false, |     port: VITE_PORT, | ||||||
|     alias: { |     open: VITE_OPEN, | ||||||
|         '/@/': path.resolve(__dirname, './src') |     base: process.env.NODE_ENV === "production" ? "./" : VITE_PUBLIC_PATH, | ||||||
|     }, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default viteConfig | export default viteConfig | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user