duidui_admin_web/Makefile
2026-03-27 10:38:12 +08:00

82 lines
2.2 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

.PHONY: build build-prod tar clean dev preview lint
# 变量定义
IMAGE_NAME := duidui-admin-web
TAR_FILE := deploy/duidui-admin-web.tar
DEPLOY_DIR := deploy
# 生产环境 API 地址
PROD_API_URL := https://admin.duiduiedu.com/admin/v1
# 构建前端项目(开发环境)
build:
@echo "构建前端项目(开发环境)..."
@npm run build
@echo "✅ 构建完成: dist/"
# 构建前端项目(生产环境,先 clean 再构建,保证 dist 为全新)
build-prod: clean
@echo "=========================================="
@echo "步骤 1: 配置生产环境 API 地址"
@echo "=========================================="
@echo "✅ 使用生产环境 API 地址: $(PROD_API_URL)"
@echo ""
@echo "=========================================="
@echo "步骤 2: 构建前端项目"
@echo "=========================================="
@VITE_API_BASE_URL=$(PROD_API_URL) npm run build
@echo "✅ 构建完成: dist/"
@echo ""
@echo "=========================================="
@echo "步骤 3: 验证构建结果"
@echo "=========================================="
@if [ ! -d "dist" ]; then \
echo "❌ 错误: dist 目录不存在"; \
exit 1; \
fi
@if grep -q "admin.duiduiedu.com" dist/assets/*.js 2>/dev/null; then \
echo "✅ 已确认使用生产环境 API 地址"; \
else \
echo "⚠️ 警告: 未找到生产环境 API 地址,请检查构建配置"; \
fi
# 开发模式运行
dev:
@echo "启动开发服务器..."
@npm run dev
# 预览构建结果
preview:
@echo "预览构建结果..."
@npm run preview
# 代码检查
lint:
@echo "运行代码检查..."
@npm run lint
# 打包部署(先构建生产 dist再打 tar 包)
tar: build-prod
@echo ""
@echo "=========================================="
@echo "步骤 4: 创建部署包"
@echo "=========================================="
@if [ ! -d "dist" ]; then \
echo "❌ 错误: dist 目录不存在,构建失败"; \
exit 1; \
fi
@chmod +x build-deploy.sh
@./build-deploy.sh
@echo ""
@echo "=========================================="
@echo "✅ 部署包创建完成: $(TAR_FILE)"
@echo "=========================================="
# 清理构建产物
clean:
@echo "清理构建产物..."
@rm -rf dist/
@rm -f $(TAR_FILE)
@echo "✅ 清理完成"