Browse Source

fix: 修复小程序开发版预览上传流程

- 开发版预览现在会自动重新构建 development 环境
- 移除开发版默认跳过构建的逻辑
- 添加 --no-build 参数选项用于跳过构建
- 更新文档说明 watch 模式输出过大导致超过 2MB 限制的问题

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 3 weeks ago
parent
commit
5415799925

+ 29 - 0
.claude/skills/weapp-publish/SKILL.md

@@ -37,6 +37,35 @@ VERSION=1.2.0 DESC="新增功能" pnpm run publish:enterprise
 
 ## 发布流程
 
+### 自动构建说明
+
+**重要**: 开发版预览会**自动重新构建** `development` 环境,确保使用最新代码。
+
+**为什么开发版需要重新构建?**
+
+微信小程序开发版预览有 **2MB 大小限制**,而使用 `pnpm run dev:weapp`(watch 模式)生成的开发版输出体积较大(通常超过 2MB),会导致上传失败:
+
+```
+errcode: 80051, errmsg: source size 2368KB exceed max limit 2MB
+```
+
+因此开发版预览必须使用 `NODE_ENV=development` 进行完整构建,这样可以:
+- 控制输出大小在限制内(约 1.3MB)
+- 确保使用最新代码
+- 避免因 watch 模式输出过大导致上传失败
+
+**构建环境说明**:
+- **开发版预览**: 使用 `NODE_ENV=development` 构建,输出到 `dist/weapp/development/`
+- **体验版**: 使用 `NODE_ENV=production` 构建,输出到 `dist/weapp/production/`
+
+如需跳过构建(使用已有构建输出),可添加 `--no-build` 参数:
+
+```bash
+node .claude/skills/weapp-publish/scripts/publish-weapp.js enterprise dev --no-build
+```
+
+### 发布步骤
+
 1. 构建项目(Taro 编译)
 2. 上传到微信服务器
 3. 生成体验版或预览二维码

+ 4 - 11
.claude/skills/weapp-publish/scripts/publish-weapp.js

@@ -32,7 +32,7 @@ const MINI_CONFIGS = {
  * 获取构建配置(根据 action 类型动态选择)
  *
  * 说明:
- * - dev (开发版预览): 使用 development 模式,跳过构建(使用 watch 模式的输出)
+ * - dev (开发版预览): 使用 development 模式,自动构建
  * - experience (体验版): 使用 production 模式,自动构建(体验版=生产环境)
  * - production (正式版): 使用 production 模式,自动构建
  *
@@ -244,14 +244,7 @@ function updatePackageVersion(config, version) {
 async function main() {
   const args = process.argv.slice(2)
 
-  // 开发版默认跳过构建(使用已有的 watch 模式构建输出)
-  // 可以通过 --build 参数强制重新构建
-  const forceBuildIndex = args.indexOf('--build')
-  const forceBuild = forceBuildIndex !== -1
-  if (forceBuild) {
-    args.splice(forceBuildIndex, 1)
-  }
-
+  // --no-build 参数可以跳过构建(默认会自动构建)
   const noBuildIndex = args.indexOf('--no-build')
   const noBuild = noBuildIndex !== -1
   if (noBuild) {
@@ -260,8 +253,8 @@ async function main() {
 
   const [miniType, action = 'experience'] = args
 
-  // 开发版默认跳过构建(除非指定 --build)
-  const shouldSkipBuild = action === 'dev' && !forceBuild
+  // 只有指定 --no-build 时才跳过构建
+  const shouldSkipBuild = noBuild
 
   // 获取构建配置(需要提前获取以便读取版本号)
   const config = getBuildConfig(MINI_CONFIGS[miniType], action)