OpenParable
Skip to content
← Back to skills

Nutui Taro Weapp Wxss

Development
nutui-taro-weapp-wxss

Nutui Taro Weapp Wxss is an Agent Skill for development published in the jdf2e/nutui-react repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

NutUI React Taro 小程序 WXSS 编译超时修复:nutui-taro-demo 样式 bundle 合并、 删除无效 renderingMode、app-origin.wxss 体积治理。Use when 微信小程序报 [ WXSS 文件编译错误] something must be wrong、wcsc timeout、app-origin.wxss 过大、predev:taro 重写 app.config、或修改 generate-nutui-taro.js / nutui.react.scss.taro.bundle.scss。

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/jdf2e/nutui-react/blob/HEAD/.cursor/skills/nutui-taro-weapp-wxss/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/nutui-taro-weapp-wxss, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

NutUI Taro 小程序 WXSS 编译治理

1. 背景与根因

现象:[ WXSS 文件编译错误] something must be wrong + Error: timeout;偶发 无效的 app.json ["renderingMode"]。

根因:app.ts → nutui.react.scss.taro.ts 曾 100+ 条独立 import 组件 scss;Taro sass.resource 向每个文件注入 variables.scss + theme-default.scss(含 base64 @font-face)。

指标修复前修复后(bundle)
app-origin.wxss~4MB~0.3–0.9MB
@font-face 重复~216~2–10

不是单个组件(如 switch.scss)的 bug,而是 demo 全量样式打包方式 导致。

数据流(修复后):

app.ts → nutui.react.scss.taro.ts → nutui.react.scss.taro.bundle.scss
  ├─ variables + theme(各 1 次)
  └─ 全部组件 scss → dist/weapp/app-origin.wxss

2. 最小改动清单

文件改动
scripts/taro/generate-nutui-taro.js新增 bundleScssStr;遍历组件拼 @import;nutui.react.scss.taro.ts 改为单 import bundle;新增写 nutui.react.scss.taro.bundle.scss
src/packages/nutui.react.scss.taro.bundle.scssvariables/theme + 全部组件 @import(自动生成,勿手改)
scripts/build-taro.mjsbuildCSS / buildHarmonyCSS 的 glob 排除 nutui.react.scss.taro.bundle.scss,避免打进 npm 按组件发包
scripts/harmony/update-taro-entry.js删除 renderingMode: 'mixed'
scripts/taro/generate-taro-route.js同上
  • nutui.react.scss.ts(H5)不变,generate-nutui.js 仍生成 100+ 条 JS import
  • 勿只改 app.config.ts:predev:taro 会跑 update-taro-entry.js 覆盖
  • 不在最小集:config/index.js minimize、各组件 scss calc 优化、package.json dev:weapp

边界说明(H5 / 发包)

场景是否走 bundle说明
H5 文档站 sites/mobile + nutui.react.scss.ts否Vite additionalData 只注入 variables,theme 在 main.tsx 单独 import 一次,无 wcsc 超时问题
Taro demo dev:taro(weapp / h5)是app.ts → nutui.react.scss.taro.ts → bundle
Taro 发包 build:taro否bundle 被 glob exclude;构建结束会删除 nutui.react.scss.js;业务方仍 import '@nutui/nutui-react-taro/dist/es/packages/xxx/style'

3. 解决 / 好处 / 影响

解决:WXSS 超时;无效 renderingMode 警告;demo 可预览(需登录开发者工具 + 清缓存)。

好处:样式单入口;不改 build:taro 发包;新增组件仍由 generate-nutui-taro.js 写入 bundle。

命令影响
dev:taro weapp有
build:taro / build:taro:demo无(bundle 已在 build-taro.mjs glob 中排除)
prepare / generate:file:taro有(再生 bundle)
VITE_APP_PROJECT_ID=jmappbundle 写死 default 主题,需另行验证

已知限制:build:weapp 生产压缩时 postcss-calc 可能破坏嵌套 var+calc(dev 无此问题);游客模式 webapi_getwxaasyncsecinfo:fail 为环境问题。


4. 验证

pnpm run dev:taro weapp
wc -c packages/nutui-taro-demo/dist/weapp/app-origin.wxss
grep -c '@font-face' packages/nutui-taro-demo/dist/weapp/app-origin.wxss

期望:体积远小于 4MB;@font-face 为个位数。


5. 未采纳方案(备查)

方案未采纳原因
各组件 scss 局部 CSS 变量非主因,扩大 diff
config/index.js minimize(false)dev 不需要
webpackImporter: false引发 Module not found
sass.resource 置空嵌套 @import(popup→overlay)缺变量
手改 app.config.tspredev:taro 会覆盖

6. Agent 自检

  • 只改生成脚本 + bundle + build-taro.mjs exclude,未扩大组件 scss diff?
  • build-taro.mjs 已排除 nutui.react.scss.taro.bundle.scss?
  • 两个生成脚本已去掉 renderingMode?
  • 仍超时:查 app-origin.wxss 体积、游客模式、是否未重新 dev