nodeBuild.js 771 B

1234567891011121314151617181920212223242526272829
  1. const { execSync } = require('child_process');
  2. const buildName = process.argv[2] //打包后的名字
  3. // 执行命令并打印输出
  4. function runCommand(command) {
  5. console.log(`执行命令: ${command}`);
  6. try {
  7. execSync(command, { stdio: 'inherit' });
  8. } catch (error) {
  9. console.error(`命令执行失败: ${error.message}`);
  10. process.exit(1);
  11. }
  12. }
  13. // 打包前的准备
  14. runCommand(`node ./scripts/build/config.js ${buildName}`);
  15. // 执行打包命令
  16. runCommand('vue-cli-service build');
  17. // 恢复配置文件
  18. runCommand('node ./scripts/build/restore.js');
  19. // 执行打包为zip
  20. runCommand(`node ./scripts/build/zip.js ${buildName}`);
  21. console.log(`----------------------------`)
  22. console.log(`${buildName} 编译打包完成`)