h5_for_webserver.build.js 895 B

123456789101112131415161718192021222324252627
  1. // 执行脚本 taro build --type h5 ,并且把环境变量 TARO_API_URL 传递过去
  2. const { execSync } = require('child_process');
  3. const path = require('path');
  4. const TARO_API_URL = ''; //
  5. const TARO_MQTT_URL ='ws://localhost:8083/mqtt';
  6. const rootDir = path.join(__dirname, '..'); // 项目根目录
  7. execSync(`taro build --type h5`, { cwd: rootDir, stdio: 'inherit', env: { ...process.env, TARO_API_URL ,TARO_MQTT_URL} }, (error, stdout, stderr) => {
  8. if (error) {
  9. console.error(`Error executing command: ${error.message}`);
  10. return;
  11. }
  12. if (stderr) {
  13. console.error(`Command stderr: ${stderr}`);
  14. return;
  15. }
  16. console.log(`Command stdout: ${stdout}`);
  17. });
  18. try {
  19. execSync('npm run pkg', { stdio: 'inherit', cwd: rootDir });
  20. } catch (err) {
  21. console.error('Failed to execute npm run pkg:', err.message);
  22. process.exit(1);
  23. }