weapp-vite-best-practices
Original:🇺🇸 English
Not Translated
Apply production-ready best practices for weapp-vite projects. Use when creating or refactoring mini-program projects with weapp-vite, designing directory/config conventions, choosing subpackage and chunk strategy, enabling auto routes/components, setting CI/devtool workflows, or debugging build/output issues in `vite.config.ts` and `app.json`.
1installs
Sourceweapp-vite/weapp-vite
Added on
NPX Install
npx skill4agent add weapp-vite/weapp-vite weapp-vite-best-practicesSKILL.md Content
weapp-vite-best-practices
Overview
Build and maintain weapp-vite projects with stable conventions first, then tune performance and build behavior. Prefer minimal config that matches project structure.
Workflow
- Confirm baseline
- Use Node and consistent pnpm.
^20.19.0 || >=22.12.0 - Ensure WeChat DevTools service port is enabled before using workflows.
--open - Verify matches real source root (
weapp.srcRootorsrc).miniprogram
- Define project structure
- Keep pages under and subpackages under
src/pages/**.src/packages/** - Keep reusable components in and shared logic in
src/components/**orsrc/shared/**.src/utils/** - Prefer explicit config layering: Vite in , mini-program specifics in
vite.config.tsfield.weapp
- Apply high-value defaults
- Enable when using convention-based pages.
weapp.autoRoutes - Keep auto component import on by default; only add custom when needed.
globs/resolvers - Use Script Setup JSON macros or blocks for page/component config instead of scattered manual JSON edits.
<json>
- Choose subpackage strategy intentionally
- Use normal subpackages for shared build context.
- Use independent subpackages only when strict isolation is needed.
- Choose by goal:
weapp.chunks.sharedStrategy- : better subpackage first-open experience.
duplicate - : better total package deduplication/control.
hoist
- Keep build and CI deterministic
- Use stable scripts (,
dev,build, optionalopen).analyze - In CI, separate compile and IDE/preview/upload steps.
- For CLI automation, prefer and non-interactive mode.
weapp-ide-cli
- Debug with framework hooks
- Use for missing output and resolution issues.
weapp.debug.watchFiles/resolveId/load - Use (plugin hook timings) for slow build diagnosis.
inspect - Validate route/component generation artifacts (, auto import outputs).
typed-router.d.ts
Guardrails
- Avoid customizing config before confirming and output roots are correct.
srcRoot - Avoid mixing many advanced chunk overrides early; start from default strategy and add targeted rules.
- Avoid treating mini-program config as web-only conventions; keep , subpackage roots, and JSON semantics explicit.
usingComponents
Completion Checklist
- has clear
vite.config.tssection with minimal required options.weapp - source-of-truth strategy is clear (manual or auto routes).
pages/subPackages - Component registration strategy is consistent (auto import + resolver policy documented).
- Subpackage/chunk strategy is chosen and justified.
- Dev/CI workflow is repeatable and does not depend on manual IDE steps.
References
references/config-playbook.mdreferences/debug-playbook.md