h5_for_production.js 960 B

1234567891011121314151617181920212223242526
  1. // 执行脚本 taro build --type h5 ,并且把环境变量 TARO_API_URL 传递过去
  2. const { execSync } = require('child_process');
  3. const path = require('path');
  4. const TARO_API_URL = 'http://localhost:6001'; // 远程地址,这里写死,要做成部署后可配置
  5. const TARO_MQTT_URL ='ws://localhost:8083/mqtt';
  6. const rootDir = path.join(__dirname, '..'); // 项目根目录
  7. try {
  8. execSync(`npm run build:h5`, { cwd: rootDir, stdio: 'inherit', env: { ...process.env, TARO_API_URL ,TARO_MQTT_URL} }, (error, stdout, stderr) => {
  9. if (error) {
  10. console.error(`Error executing command: ${error.message}`);
  11. return;
  12. }
  13. if (stderr) {
  14. console.error(`Command stderr: ${stderr}`);
  15. return;
  16. }
  17. console.log(`Command stdout: ${stdout}`);
  18. });
  19. console.log('\n✅ h5 for production 全部构建完成');
  20. } catch (err) {
  21. console.error('Failed to execute :', err.message);
  22. process.exit(1);
  23. }