119 lines
4.7 KiB
PowerShell
119 lines
4.7 KiB
PowerShell
# uni-app 构建辅助脚本
|
||
# 此脚本帮助您理解构建流程并检查构建结果
|
||
|
||
param(
|
||
[Parameter(Mandatory=$false)]
|
||
[ValidateSet('h5', 'mp-weixin', 'app')]
|
||
[string]$Platform = 'app'
|
||
)
|
||
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host "uni-app 项目构建辅助工具" -ForegroundColor Cyan
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
|
||
# 检查 node_modules
|
||
if (-not (Test-Path "node_modules")) {
|
||
Write-Host "❌ 未找到 node_modules 目录" -ForegroundColor Red
|
||
Write-Host "正在安装依赖..." -ForegroundColor Yellow
|
||
npm install
|
||
if ($LASTEXITCODE -ne 0) {
|
||
Write-Host "❌ 依赖安装失败" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
}
|
||
|
||
Write-Host "✅ 依赖检查完成" -ForegroundColor Green
|
||
Write-Host ""
|
||
|
||
# 清理旧的构建文件
|
||
Write-Host "🧹 清理旧的构建文件..." -ForegroundColor Yellow
|
||
$buildPath = "unpackage\dist\build\$Platform"
|
||
if (Test-Path $buildPath) {
|
||
Remove-Item -Path $buildPath -Recurse -Force
|
||
Write-Host "✅ 已清理: $buildPath" -ForegroundColor Green
|
||
}
|
||
Write-Host ""
|
||
|
||
# 执行构建
|
||
Write-Host "🔨 开始构建 $Platform 平台..." -ForegroundColor Yellow
|
||
Write-Host "执行命令: npm run build:$Platform" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
|
||
npm run "build:$Platform"
|
||
|
||
if ($LASTEXITCODE -ne 0) {
|
||
Write-Host ""
|
||
Write-Host "❌ 构建失败" -ForegroundColor Red
|
||
exit 1
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "========================================" -ForegroundColor Green
|
||
Write-Host "✅ 构建完成!" -ForegroundColor Green
|
||
Write-Host "========================================" -ForegroundColor Green
|
||
Write-Host ""
|
||
|
||
# 显示构建结果
|
||
Write-Host "📦 构建产物位置:" -ForegroundColor Cyan
|
||
$outputPath = "unpackage\dist\build\$Platform"
|
||
if (Test-Path $outputPath) {
|
||
Write-Host " $outputPath" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "📁 构建文件列表:" -ForegroundColor Cyan
|
||
Get-ChildItem -Path $outputPath | ForEach-Object {
|
||
$size = if ($_.PSIsContainer) { "(目录)" } else { "($([math]::Round($_.Length/1KB, 2)) KB)" }
|
||
Write-Host " - $($_.Name) $size" -ForegroundColor White
|
||
}
|
||
} else {
|
||
Write-Host " ⚠️ 未找到构建产物" -ForegroundColor Yellow
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host "⚠️ 重要提示" -ForegroundColor Yellow
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
|
||
if ($Platform -eq 'app') {
|
||
Write-Host ""
|
||
Write-Host "📱 App 平台说明:" -ForegroundColor Yellow
|
||
Write-Host ""
|
||
Write-Host "当前构建只生成了编译后的代码文件," -ForegroundColor White
|
||
Write-Host "并没有生成可安装的 APK 或 IPA 文件。" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "要生成安装包,您需要:" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
Write-Host "方案 1(推荐):使用 HBuilderX" -ForegroundColor Green
|
||
Write-Host " 1. 下载 HBuilderX: https://www.dcloud.io/hbuilderx.html" -ForegroundColor White
|
||
Write-Host " 2. 在 HBuilderX 中打开本项目" -ForegroundColor White
|
||
Write-Host " 3. 点击菜单: 发行 -> 原生App-云打包" -ForegroundColor White
|
||
Write-Host " 4. 选择平台并配置证书" -ForegroundColor White
|
||
Write-Host " 5. 等待打包完成并下载安装包" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "方案 2(高级):使用离线打包" -ForegroundColor Green
|
||
Write-Host " 1. 下载 uni-app 离线 SDK" -ForegroundColor White
|
||
Write-Host " 2. 配置 Android Studio 或 Xcode" -ForegroundColor White
|
||
Write-Host " 3. 将构建产物复制到 SDK 中" -ForegroundColor White
|
||
Write-Host " 4. 使用原生 IDE 打包" -ForegroundColor White
|
||
Write-Host ""
|
||
Write-Host "详细说明请查看: BUILD_GUIDE.md" -ForegroundColor Cyan
|
||
} elseif ($Platform -eq 'h5') {
|
||
Write-Host ""
|
||
Write-Host "🌐 H5 平台说明:" -ForegroundColor Yellow
|
||
Write-Host ""
|
||
Write-Host "构建产物可以直接部署到 Web 服务器。" -ForegroundColor White
|
||
Write-Host "将 $outputPath 目录中的文件上传到服务器即可。" -ForegroundColor White
|
||
} elseif ($Platform -eq 'mp-weixin') {
|
||
Write-Host ""
|
||
Write-Host "📱 微信小程序说明:" -ForegroundColor Yellow
|
||
Write-Host ""
|
||
Write-Host "请使用微信开发者工具打开构建产物目录:" -ForegroundColor White
|
||
Write-Host " $outputPath" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
Write-Host "然后在微信开发者工具中上传代码。" -ForegroundColor White
|
||
}
|
||
|
||
Write-Host ""
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host ""
|