Purpose
Write pages and components in mini program projects with Vue SFC that are "predictable to compile, verifiable at runtime, and type-traceable".
When to use
- When the user asks how a
.vuefile should be written. - When the user asks how to choose between JSON macros and
<json>. - When the user asks how to configure
definePageMeta/ layout. - When the user hits template compatibility or compile errors.
- When the user hits
.weapp-vitetype output, component declarations, or route type drift. - When the user wants to use uni-app Vue SFC component libraries such as Wot UI and uview-plus in WeChat mini programs and on the Web.
- When the user wants to use template-only
.vue、<script lang="jsx">/<script setup lang="tsx">, or handle multi-platform SFC compilation differences.
Not applicable scenarios
This skill focuses on SFC authoring and compile-time compatibility.
- Project-level build configuration: use
weapp-vite-best-practices。 wevuLifecycle and store: usewevu-best-practices。- Migration planning: use
native-to-weapp-vite-wevu-migration。 - React JSX/TSX after the project enables
weapp.react: useweapp-vite-react-best-practices。
Core workflow
- First determine the problem stage:
- Compile time: macros, templates,
usingComponents - Runtime: events, hooks, reactivity
- Tooling layer: Volar,
.weapp-vite、typed outputs
- Compile time: macros, templates,
- By default use
<script setup lang="ts">。- Template-only SFC is allowed to have no script block;
wv preparemust be scanned as an SFC template; do not mistakenly hand template text to the JSX parser. - Wevu JSX/TSX and JSX/TSX inside SFC belong to the Wevu compiler; project-level
weapp.reactonce enabled, standalone.jsx/.tsxbelongs to the React owner.
- Template-only SFC is allowed to have no script block;
- Prefer macros for JSON:
defineAppJson、definePageJson、defineComponentJson; page metadata goes throughdefinePageMeta。 - Apply template compatibility rules:
v-modelcan only act on assignable lvalues- Do not assume all Web Vue template features are available
usingComponentsgo through JSON macros / auto-import, not the Web Vue registration approach- In the documentation of third-party mini program UI libraries (such as TDesign Mini Program and Vant Weapp),
TNode、slotand custom content are usually mini program native slots or attribute rendering; do not treat them as Vue scoped slots by default - Third-party uni-app Vue SFC component libraries and native mini program UI libraries are not the same path: the former requires the resolver to return
sourceType: 'wevu-sfc'/ realresolvedId, and pass throughweapp.uniApp.includeto explicitly allow dependency transformation - Only when there are explicit slot props (such as
<template #item="{ item }">) or explicit enhanced scoped slot scenarios should you generategeneric:scoped-slots-* - When forwarding
<slot />to a child component's named slot, do not generate or suggest<block slot="..."><slot /></block>; the real DevTools runtime will lose the forwarded content. The WeChat platform uses an internalvirtualHostwrapper by default; to return to the old real-node behavior, configureweapp.vue.template.slotFallbackWrapperStrategy: 'view'; for customization, prefer the component-internal static attributeslot-wrapper="cover-view"、slot-wrapper-footer="view"、slot-wrapper-class="..."、slot-wrapper-footer-class="..."or project configurationweapp.vue.template.slotFallbackWrapper; in global rules,componentmatches template tag names,componentNamematches child component staticdefineOptions({ name }) - A custom slot wrapper must be able to carry actual child content; for example,
textis not suitable for wrapping<view>,blockwill be fallen back by the compiler toview - Vue/Wevu component tag output remains kebab-case; optional chaining and nullish coalescing must be converted into expressions executable by the target mini program template
- When
weapp.i18nis enabled, import the build instanceweapp-vite/i18nfromi18n, and explicitly wire it in withdefineOptions({ behaviors: [i18n.behavior] }); the logic layer accesses translations and locale throughi18n.global, and templates can directly call the configuredt(...) - i18n only allows direct template calls of configured functions;
t(resolveKey())or other nested calls still fall back to the logic thread, do not rely on arbitrary functions executing in WXML - The WeChat target supports scoped CSS, default/named CSS Modules,
useCssModule()in synchronous setup, and CSSv-bind(); CSS vars are merged into the existing style of each template root node :deep()/:global()/:slotted()only use forms that can be mapped to mini program selectors; treat other platforms as experimental until verified in the corresponding IDE/real device
- If
typed-router.d.ts、typed-components.d.ts、components.d.tsdrifts, first runwv prepare。 - If the project has a root
AGENTS.mdor localdist/docs/vue-sfc.md, the SFC syntax must be consistent with its constraints. - For multi-platform SFC, verify only one
-p <platform>target at a time; the Web runtime is for browser compatibility integration testing and does not replace the target mini program IDE/real device.
Toolchain and hot update boundaries
- For Volar type issues, first check
.weapp-vite/tsconfig.app.json, solution references, andvueCompilerOptions.plugins; do not replace managed configuration with implicit root directory inclusion. skipTemplateCodegenwill move template bindings and WXS types out of the template context; when "property does not exist" appears, first rule out that configuration.- Rely on JSON-only HMR only when JSON macros or configuration change; behavior, template, and runtime changes are still verified through the full SFC compilation chain.
defineConfigIt is recommended to import fromweapp-vite/configto preserveweapp.*'s context types and Hover documentation.
For the detailed matrix, see references/tooling-and-hmr-matrix.md。
Constraints
- Do not mix multiple sets of JSON macros in one SFC.
- Do not treat mini program component registration as Web Vue component registration.
- Do not configure only the Wot UI or uview-plus resolver while omitting
weapp.uniApp.include, and do not automatically add npm dependencies to the transformation scope. uview-plus should callmount$u()and synchronize$u, do not go through the Web global component registration process. - Do not mistake the ordinary default slot of kebab-case third-party native components such as
t-*、van-*for an enhanced scoped slot. - Do not ignore
prepareand.weapp-viteartifacts. - Do not casually perform unrelated runtime refactoring while fixing SFC syntax.
- Do not treat the built-in i18n as an ICU/MessageFormat runtime; v1 only supports simple key lookup and
{name}/{user.name}interpolation.
Output
When applying this skill, the output must include:
- Problem stage diagnosis.
- SFC-level change recommendations.
- Template compatibility considerations.
- Minimal verification commands.
Completion markers
- Macro usage is clear and singular.
- The template does not use unsupported syntax.
usingComponentsThe path is safe and the source is clear..weapp-viteSupport for file and type output has been synchronized.
References
references/macro-config-checklist.mdreferences/template-compat-matrix.mdreferences/troubleshooting-playbook.mdreferences/tooling-and-hmr-matrix.md