|
|
@@ -46,10 +46,16 @@ function getBuildConfig(config, action) {
|
|
|
// 根据模式设置对应的 NODE_ENV
|
|
|
// 这样构建输出目录和上传目录就能匹配了
|
|
|
const nodeEnv = mode === 'development' ? 'development' : 'production'
|
|
|
- const buildCmd = `cd ${config.dir} && NODE_ENV=${nodeEnv} pnpm taro build --type weapp`
|
|
|
+ // 小程序目录的绝对路径,用于 execSync 的 cwd 参数
|
|
|
+ const miniDir = path.resolve(PROJECT_ROOT, config.dir)
|
|
|
+ // 构建命令不需要 cd,通过 cwd 参数指定工作目录
|
|
|
+ const buildCmd = `NODE_ENV=${nodeEnv} pnpm taro build --type weapp`
|
|
|
|
|
|
return {
|
|
|
...config,
|
|
|
+ mode,
|
|
|
+ nodeEnv,
|
|
|
+ miniDir,
|
|
|
projectPath: path.resolve(PROJECT_ROOT, `${config.dir}/${config.distPath}/${mode}`),
|
|
|
buildCmd,
|
|
|
}
|
|
|
@@ -60,8 +66,10 @@ function getBuildConfig(config, action) {
|
|
|
*/
|
|
|
function buildMiniProject(config) {
|
|
|
console.log(`\n🔨 正在构建 ${config.name}...`)
|
|
|
+ console.log(` 工作目录: ${config.miniDir}`)
|
|
|
+ console.log(` 环境变量: NODE_ENV=${config.nodeEnv}`)
|
|
|
try {
|
|
|
- execSync(config.buildCmd, { stdio: 'inherit', cwd: PROJECT_ROOT, shell: true })
|
|
|
+ execSync(config.buildCmd, { stdio: 'inherit', cwd: config.miniDir, shell: true })
|
|
|
console.log(`✅ ${config.name} 构建完成`)
|
|
|
} catch (error) {
|
|
|
console.error(`❌ ${config.name} 构建失败`)
|