Files
boluo-admin-main/.docker/env.sh
2025-07-28 16:38:37 +08:00

23 lines
621 B
Bash

#!/bin/sh
# 生成环境变量配置文件
echo "window.ENV = {" > ./dist/env-config.js
# 注入 BASE_URL 环境变量
if [ -n "$BASE_URL" ]; then
echo " BASE_URL: '$BASE_URL'," >> ./dist/env-config.js
fi
# 添加其他环境变量,如有需要
# if [ -n "$API_KEY" ]; then
# echo " API_KEY: '$API_KEY'," >> ./dist/env-config.js
# fi
# 关闭对象
echo "};" >> ./dist/env-config.js
# 确保 env-config.js 被引入到 index.html
sed -i "s/<\/head>/\n<script src=\"\/env-config.js\"><\/script>\n<\/head>/g" ./dist/index.html
echo "环境变量已注入到 dist/env-config.js 并已在 index.html 中引入"