Files
assist/build_frontend.sh

83 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/bash
echo "构建TSP智能助手前端..."
echo
# 检查Node.js环境
echo "检查Node.js环境..."
if ! command -v node &> /dev/null; then
echo "错误: 未找到Node.js请先安装Node.js"
echo "安装命令:"
echo " Ubuntu/Debian: sudo apt update && sudo apt install nodejs npm"
echo " CentOS/RHEL: sudo yum install nodejs npm"
echo " 或访问: https://nodejs.org/"
exit 1
fi
# 检查npm环境
echo "检查npm环境..."
if ! command -v npm &> /dev/null; then
echo "错误: 未找到npm请检查Node.js安装"
exit 1
fi
echo "Node.js版本: $(node --version)"
echo "npm版本: $(npm --version)"
echo
# 检查Node.js版本兼容性
NODE_VERSION=$(node --version | cut -d'v' -f2 | cut -d'.' -f1)
if [ "$NODE_VERSION" -ge 22 ]; then
echo "检测到Node.js v22+,使用兼容性构建模式..."
SKIP_TYPE_CHECK=true
else
echo "使用标准构建模式..."
SKIP_TYPE_CHECK=false
fi
# 进入前端目录
cd frontend
# 检查依赖包
echo "检查依赖包..."
if [ ! -d "node_modules" ]; then
echo "安装依赖包..."
npm install
if [ $? -ne 0 ]; then
echo "错误: 依赖包安装失败"
exit 1
fi
fi
# 运行类型检查根据Node.js版本决定
if [ "$SKIP_TYPE_CHECK" = true ]; then
echo "跳过类型检查Node.js v22+兼容性模式)..."
else
echo "运行类型检查..."
npm run type-check
if [ $? -ne 0 ]; then
echo "警告: 类型检查失败,但继续构建..."
fi
fi
# 构建生产版本
echo "构建生产版本..."
if [ "$SKIP_TYPE_CHECK" = true ]; then
# 直接使用Vite构建跳过vue-tsc
echo "使用Vite直接构建跳过TypeScript检查..."
npx vite build
else
# 标准构建流程
npm run build
fi
if [ $? -ne 0 ]; then
echo "错误: 构建失败"
exit 1
fi
echo
echo "构建完成!"
echo "构建文件已输出到: ../src/web/static/dist"
echo