1 changed files with 51 additions and 0 deletions
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
# AGENTS.md |
||||
|
||||
## Project |
||||
|
||||
WeChat Mini Program (微信小程序) — school campus app. Source root is `src/` (set via `miniprogramRoot` in `project.config.json`). |
||||
|
||||
## Commands |
||||
|
||||
- **Lint:** `pnpm run lint:fix` (eslint only; no separate typecheck or test commands exist) |
||||
- **npm build:** Must use WeChat DevTools → "Build npm" menu. Output goes to `src/miniprogram_npm/` (gitignored). Do not edit `miniprogram_npm/` manually. |
||||
- **JSX compile:** `pnpm run beforeCompile` — Babel-transforms `.jsx` files under `src/pages/` using `@babel/plugin-transform-react-jsx` (automatic runtime). WeChat DevTools runs this automatically via `project.config.json` scripts before compile/preview/upload. No `.jsx` files currently exist, but the pipeline is wired. |
||||
|
||||
## Architecture |
||||
|
||||
- **Custom Page wrapper** (`src/utils/page.ts`): The global `Page` constructor is replaced in `app.ts` `onLaunch`. Every page automatically gets navbar setup, image params, scroll-based nav background, and a default `onShareAppMessage`. When adding page lifecycle hooks, be aware these wrappers run before your own handlers. |
||||
- **`wx.ajax`**: Custom property added to `wx` in `app.ts` `onLaunch`. It is a curried version of `src/api/request.ts` with the base URL baked in. Use `wx.ajax(...)` for network requests — do not call `request` directly from pages. |
||||
- **Login flow**: Managed in `App` via `globalData.loginState` / `globalData.initLoginInfo`. Pages call `getApp().waitLogin()` before making authenticated requests. |
||||
- **Custom tabbar**: `app.json` has `"custom": true`; the tabbar UI is implemented in components. |
||||
|
||||
## Path Aliases |
||||
|
||||
- `@/*` → `src/*` (configured in both `tsconfig.json` paths and `app.json` resolveAlias) |
||||
|
||||
## Style & Lint |
||||
|
||||
- ESLint: `@antfu/eslint-config` + `eslint-config-prettier` (stylistic rules off). Globals `wx`, `App`, `Page`, `Component`, `getApp`, `getCurrentPages`, `requirePlugin`, `requireMiniProgram` are declared. |
||||
- Prettier: no semicolons, single quotes, trailing commas, printWidth 120. Uses `html` parser for `.wxml`, `css` for `.wxss`, `babel` for `.wxs`. |
||||
- TypeScript: strict mode (but `noImplicitAny: false`), target ES5, CommonJS modules. Typings in `typings/index.d.ts` declare `IAppOption`, `IAgaxParams`, and extend `WechatMiniprogram.Wx` with `ajax`. |
||||
|
||||
## File Structure |
||||
|
||||
Each page/component follows the standard miniprogram quad: `.ts`, `.wxml`, `.scss`, `.json`. |
||||
|
||||
``` |
||||
src/ |
||||
app.ts / app.json / app.scss # App entry |
||||
api/request.ts # HTTP request wrapper |
||||
utils/ |
||||
page.ts # Custom Page wrapper (global) |
||||
util.ts # Helpers |
||||
dayjs/ # Manually bundled dayjs plugins (not from npm) |
||||
pages/{name}/index.{ts,wxml,scss,json} |
||||
components/{name}/index.{ts,wxml,scss,json} |
||||
``` |
||||
|
||||
## Gotchas |
||||
|
||||
- `src/utils/dayjs/` contains hand-copied dayjs locale/plugin files, not npm imports. Do not replace with npm imports without testing. |
||||
- `src/miniprogram_npm/` is build output — never edit directly. |
||||
- The `beforeCompile` Babel step only processes `src/pages/**/*.jsx`. If you add JSX outside `pages/`, the script won't catch it. |
||||
- No test framework is configured. |
||||
Loading…
Reference in new issue