You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
3.0 KiB

# 增强版开发脚本 - 解决中文编码和日志问题
param(
[switch]$Debug,
[switch]$Watch
)
# 设置控制台编码为 UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
# 设置环境变量
$env:VUE_CLI_BABEL_TRANSPILE_MODULES = "false"
$env:VUE_CLI_MODERN_BUILD = "false"
$env:VUE_CLI_LOG_LEVEL = "info"
$env:VUE_CLI_DEBUG = "true"
$env:LANG = "zh_CN.UTF-8"
$env:LC_ALL = "zh_CN.UTF-8"
$env:NODE_OPTIONS = "--max-old-space-size=4096"
# 设置Electron相关环境变量,改善DevTools兼容性
$env:ELECTRON_DISABLE_SECURITY_WARNINGS = "true"
$env:ELECTRON_ENABLE_LOGGING = "false"
$env:ELECTRON_ENABLE_STACK_DUMPING = "false"
$env:ELECTRON_NO_ASAR = "1"
$env:ELECTRON_RUN_AS_NODE = "false"
$env:ELECTRON_NO_ATTACH_CONSOLE = "true"
# 显示启动信息
Write-Host "🚀 启动 GoFaster 前端开发环境..." -ForegroundColor Cyan
Write-Host "📝 编码设置: UTF-8" -ForegroundColor Green
Write-Host "🔧 日志级别: INFO" -ForegroundColor Green
Write-Host "⚡ 热重载: 已启用" -ForegroundColor Green
Write-Host ""
# 检查依赖
Write-Host "📦 检查依赖..." -ForegroundColor Yellow
if (-not (Test-Path "node_modules")) {
Write-Host " 依赖未安装,正在安装..." -ForegroundColor Yellow
npm install
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ 依赖安装失败" -ForegroundColor Red
exit 1
}
}
# 安装 cross-env(如果不存在)
$crossEnvInstalled = npm list cross-env 2>$null
if (-not $crossEnvInstalled) {
Write-Host "📦 安装 cross-env..." -ForegroundColor Yellow
npm install --save-dev cross-env
}
Write-Host "✅ 依赖检查完成" -ForegroundColor Green
Write-Host ""
# 选择运行模式
if ($Debug) {
Write-Host "🐛 调试模式启动..." -ForegroundColor Magenta
$env:DEBUG = "*"
$script = "npm run dev:debug"
} elseif ($Watch) {
Write-Host "👀 监听模式启动..." -ForegroundColor Blue
$script = "npm run dev:watch"
} else {
Write-Host "🚀 标准模式启动..." -ForegroundColor Green
$script = "npm run dev"
}
Write-Host ""
Write-Host "💡 提示:" -ForegroundColor Cyan
Write-Host " - 使用 -Debug 参数启用详细调试信息" -ForegroundColor White
Write-Host " - 使用 -Watch 参数启用文件监听" -ForegroundColor White
Write-Host " - 按 Ctrl+C 停止服务" -ForegroundColor White
Write-Host ""
# 启动服务
Write-Host " 执行命令: $script" -ForegroundColor Yellow
Write-Host ""
try {
Invoke-Expression $script
} catch {
Write-Host "❌ 启动失败: $($_.Exception.Message)" -ForegroundColor Red
Write-Host ""
Write-Host "🔧 故障排除:" -ForegroundColor Yellow
Write-Host " 1. 检查 Node.js 版本 (推荐 v16+)" -ForegroundColor White
Write-Host " 2. 清除 node_modules 并重新安装" -ForegroundColor White
Write-Host " 3. 检查端口占用情况" -ForegroundColor White
Write-Host " 4. 查看详细错误日志" -ForegroundColor White
exit 1
}