@liujitcn/kratos-taro-app-cli 0.0.42 → 0.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,3 +38,5 @@ CLI 直接生成完整宿主、本地业务模块、四种语言源文件与注
38
38
  新增语言或修改语言文件后运行 `pnpm i18n:sync`;`pnpm i18n:check` 校验注册文件是否同步。
39
39
 
40
40
  H5 宿主通过 `esnextModules` 将已装配 npm 源码包加入 Taro 样式处理,确保 px 按 750 设计稿转换为 rem;仅设置脚本的 `compile.include` 无法覆盖样式转换。第三方组件仍遵循 Taro 默认处理规则。
41
+
42
+ 构建产物按模式与平台隔离:开发使用 `dist/dev/h5`、`dist/dev/mp-weixin`,生产默认使用 `dist/build/h5`、`dist/build/mp-weixin`。`KRATOS_TARO_OUTPUT_ROOT` 可覆盖默认目录;仓库宿主及 Kratos 配套项目的 H5 生产构建输出到 `backend/data/taro-app`。微信开发者工具默认指向开发目录,发布时导入生产目录。
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "type": "git",
8
8
  "url": "git@github.com:liujitcn/kratos-admin.git"
9
9
  },
10
- "version": "0.0.42",
10
+ "version": "0.0.44",
11
11
  "type": "module",
12
12
  "bin": {
13
13
  "kratos-taro-app": "./bin/kratos-taro-app.mjs"
package/src/index.mjs CHANGED
@@ -117,6 +117,8 @@ pnpm build:mp-weixin
117
117
  pnpm tsc
118
118
  \`\`\`
119
119
 
120
+ 开发产物位于 apps/taro-app/dist/dev/<平台>,生产产物位于 apps/taro-app/dist/build/<平台>(平台为 h5 或 mp-weixin);Kratos 配套项目的 H5 生产产物输出到 backend/data/taro-app。微信开发者工具默认使用 dist/dev/mp-weixin,发布时导入 dist/build/mp-weixin。
121
+
120
122
  模块装配入口是 \`apps/taro-app/src/module-manifest.ts\`。模块顺序决定静态视图覆盖优先级;新增页面时同步维护模块自己的 \`src/pages.ts\` 和视图映射。
121
123
 
122
124
  环境文件位于 workspace 根目录,变量名与 uni-app 保持一致:\`VITE_APP_PORT\`、\`VITE_APP_BASE_PATH\`、\`VITE_APP_BASE_API\`、\`VITE_APP_API_URL\`、\`VITE_APP_STATIC_API\`、\`VITE_APP_STATIC_URL\`。H5 会在基础模式文件上叠加对应的 \`*-h5\` 文件。
@@ -209,6 +211,8 @@ function writeHost(target, projectName, modules, packages, options) {
209
211
 
210
212
  \`apps/taro-app\` 是 \`${projectName}\` 的私有 Taro React 宿主,负责装配模块并提供 H5、微信小程序构建入口,不承载可复用业务实现。
211
213
 
214
+ 开发产物位于 apps/taro-app/dist/dev/<平台>,生产产物位于 apps/taro-app/dist/build/<平台>(平台为 h5 或 mp-weixin);Kratos 配套项目的 H5 生产产物输出到 backend/data/taro-app。微信开发者工具默认使用 dist/dev/mp-weixin,发布时导入 dist/build/mp-weixin。
215
+
212
216
  固定启动页位于 \`src/pages/bootstrap\`。其他模块页面由 core runner 在构建期间临时生成包装器、页面配置与静态资源,构建结束后会自动恢复宿主目录。
213
217
 
214
218
  通过局域网 IP 访问 H5 时,可复用仓库根 certs 下的共享证书,并在 .env.development-h5.local 中设置 VITE_APP_HTTPS=true;后端使用 HTTPS 时同步设置 VITE_APP_API_URL=https://localhost:7001。
@@ -241,7 +245,7 @@ function writeHost(target, projectName, modules, packages, options) {
241
245
  target,
242
246
  'apps/taro-app/project.config.json',
243
247
  json({
244
- miniprogramRoot: './dist/build/mp-weixin',
248
+ miniprogramRoot: './dist/dev/mp-weixin',
245
249
  projectname: projectName,
246
250
  description: `${projectName} Taro React application`,
247
251
  appid: '',
@@ -471,12 +475,28 @@ function resolveHttpsOptions(env: Record<string, string>, root: string) {
471
475
  }
472
476
 
473
477
  function resolveEnv(mode: string, platform: string): Record<string, string> {
474
- const baseEnv = dotenvParse(workspaceRoot, 'VITE_APP_', mode)
475
- const platformEnv =
476
- platform === 'h5' ? dotenvParse(workspaceRoot, 'VITE_APP_', \`\${mode}-\${platform}\`) : {}
477
478
  const shellEnv = Object.fromEntries(
478
479
  Object.entries(process.env).filter(([key]) => key.startsWith('VITE_APP_')),
479
480
  ) as Record<string, string>
481
+ const parseEnv = (envMode: string) => {
482
+ const savedEnv = Object.fromEntries(
483
+ Object.entries(process.env).filter(([key]) => key.startsWith('VITE_APP_')),
484
+ ) as Record<string, string>
485
+ try {
486
+ Object.keys(process.env)
487
+ .filter((key) => key.startsWith('VITE_APP_'))
488
+ .forEach((key) => delete process.env[key])
489
+ return dotenvParse(workspaceRoot, 'VITE_APP_', envMode)
490
+ } finally {
491
+ Object.keys(process.env)
492
+ .filter((key) => key.startsWith('VITE_APP_'))
493
+ .forEach((key) => delete process.env[key])
494
+ Object.assign(process.env, savedEnv)
495
+ }
496
+ }
497
+ const baseEnv = parseEnv(mode)
498
+ const platformEnv =
499
+ platform === 'h5' ? parseEnv(\`\${mode}-\${platform}\`) : {}
480
500
  return { ...baseEnv, ...platformEnv, ...shellEnv }
481
501
  }
482
502
 
@@ -484,13 +504,10 @@ export default defineConfig<'webpack5'>(async (merge) => {
484
504
  const mode = process.env.NODE_ENV || 'production'
485
505
  const platform = process.env.TARO_ENV || ''
486
506
  const env = resolveEnv(mode, platform)
507
+ const outputMode = mode === 'development' ? 'dev' : 'build'
487
508
  const outputRoot =
488
509
  process.env.KRATOS_TARO_OUTPUT_ROOT ||
489
- (platform === 'h5'
490
- ? 'dist/h5'
491
- : platform === 'weapp'
492
- ? 'dist/mp-weixin'
493
- : 'dist')
510
+ 'dist/' + outputMode + '/' + (platform === 'weapp' ? 'mp-weixin' : platform || 'h5')
494
511
  const publicPath = env.VITE_APP_BASE_PATH ?? '/'
495
512
  const apiBasePath = env.VITE_APP_BASE_API ?? '/api'
496
513
  const apiTargetUrl = env.VITE_APP_API_URL ?? 'http://localhost:7001'
@@ -4,15 +4,15 @@
4
4
  "private": true,
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "scripts": {
7
- "prepare:modules": "pnpm --recursive --filter './packages/modules/**' --if-present run build:entries",
7
+ "prepare:modules": "pnpm --silent --recursive --filter './packages/modules/**' --if-present run build:entries",
8
8
  "dev:h5": "pnpm prepare:modules && pnpm --filter @local/kratos-taro-app dev:h5",
9
9
  "dev:mp-weixin": "pnpm prepare:modules && pnpm --filter @local/kratos-taro-app dev:mp-weixin",
10
- "build:h5": "pnpm prepare:modules && pnpm --filter @local/kratos-taro-app build:h5",
11
- "build:mp-weixin": "pnpm prepare:modules && pnpm --filter @local/kratos-taro-app build:mp-weixin",
12
- "tsc": "pnpm --recursive --if-present run tsc",
10
+ "build:h5": "pnpm --silent prepare:modules && pnpm --silent --filter @local/kratos-taro-app build:h5",
11
+ "build:mp-weixin": "pnpm --silent prepare:modules && pnpm --silent --filter @local/kratos-taro-app build:mp-weixin",
12
+ "tsc": "pnpm --silent --recursive --if-present run tsc",
13
13
  "test": "node --test",
14
- "build:packages": "pnpm --recursive --filter './packages/modules/**' run build",
15
- "check:exports": "pnpm run prepare:modules && node scripts/check-package-exports.mjs",
14
+ "build:packages": "pnpm --silent --recursive --filter './packages/modules/**' run build",
15
+ "check:exports": "pnpm --silent run prepare:modules && node scripts/check-package-exports.mjs",
16
16
  "lint": "eslint . --fix --ext .js,.mjs,.ts,.tsx",
17
17
  "i18n:sync": "node scripts/sync-locales.mjs --write",
18
18
  "i18n:check": "node scripts/sync-locales.mjs"