37 lines
1.9 KiB
Markdown
37 lines
1.9 KiB
Markdown
# README
|
|
|
|
`@umijs/max` 模板项目,更多功能参考 [Umi Max 简介](https://umijs.org/docs/max/introduce)
|
|
|
|
## Language Switching
|
|
|
|
- Lang toggle components (`src/components/switch/LangSwitches.tsx`, `src/components/LanguageSwitcher/index.tsx`) call Umi `setLocale(newLocale, false)` so content re-renders instantly without refreshing the page.
|
|
- Both components listen for the browser `languagechange` event to keep their UI state in sync when another part of the app switches languages.
|
|
- Strings are translated via `useTranslation`/`useIntl`; ensure new labels have entries in `src/locales/en-US.ts` and `src/locales/vi-VN.ts`.
|
|
|
|
## Proxy & Request Profiles
|
|
|
|
- Project uses two sets of configs under `config/`:
|
|
- `proxy.ts` + `Request.ts` for local development API targets.
|
|
- `proxy_prod.ts` + `request_prod.ts` for production-like targets.
|
|
- The runtime selects configs automatically:
|
|
- `pnpm run dev` / any dev server run ⇒ `NODE_ENV=development` ⇒ uses dev proxy/request.
|
|
- `pnpm run build` (and other production builds) ⇒ `NODE_ENV=production` ⇒ uses prod proxy/request.
|
|
- Override the environment by exporting `REACT_APP_ENV` before running commands (values: `dev`, `test`, `prod`). Example:
|
|
|
|
```bash
|
|
# Use test upstreams in a dev session
|
|
REACT_APP_ENV=test pnpm run dev
|
|
|
|
# Build with testing endpoints
|
|
NODE_ENV=production REACT_APP_ENV=test pnpm run build
|
|
```
|
|
|
|
- `config/proxy_prod.ts` resolves targets dynamically based on the current hostname; adjust rules there if deployment hosts change.
|
|
- `config/request_prod.ts` prepends the API base URL from `ApiConfigService`, while the dev file leaves relative paths untouched.
|
|
|
|
## Verifying Builds
|
|
|
|
- After switching language, confirm UI updates immediately and check console for `languagechange` events.
|
|
- For proxy changes, inspect network requests in devtools to ensure they hit the expected environment.
|
|
- Run `pnpm run build && pnpm serve` (or your hosting preview) to validate prod settings before deploying.
|