yuan
5 天以前 9ea5ff67655241271bdf04bb50ca3a8d60c4e22a
multiple/multiple-build.js
@@ -60,12 +60,15 @@
    const backupFile = path.join(replacePath, config[key]);
    const replaceFile = path.join(resourcePath, companyMap[key]);
    await copyFileWithOverwrite(originFile, backupFile);
    if (fsSync.existsSync(originFile)) {
      await copyFileWithOverwrite(originFile, backupFile);
    }
    await copyFileWithOverwrite(replaceFile, originFile);
  }
  console.log("=====开始打包=====");
  execSync("vite build", { stdio: "inherit" });
  const buildEnv = createBuildEnv(companyMap.env);
  execSync("vite build", { stdio: "inherit", cwd: rootPath, env: buildEnv });
  console.log("=====打包完成======");
} finally {
  console.log("=====恢复资源======");
@@ -81,7 +84,9 @@
      const originFile = path.join(rootPath, config[key]);
      const backupFile = path.join(replacePath, config[key]);
      await copyFileWithOverwrite(backupFile, originFile);
      if (fsSync.existsSync(backupFile)) {
        await copyFileWithOverwrite(backupFile, originFile);
      }
    }
    await fs.rm(replacePath, { recursive: true, force: true });
    console.log(`🗑️ 已删除 ${replacePath}`);
@@ -135,3 +140,17 @@
  if (!trimmed) return undefined;
  return trimmed.replace(/^["']|["']$/g, "");
}
function createBuildEnv(companyEnv) {
  const env = { ...process.env };
  for (const key of Object.keys(env)) {
    if (key.startsWith("VITE_")) {
      delete env[key];
    }
  }
  return {
    ...env,
    ...companyEnv,
    VITE_APP_ENV: "production",
  };
}