docs: 完善安装指南并增强启动脚本功能
- 扩展 README.md 中的安装说明,增加环境要求、详细步骤和常见问题排查 - 重写 start.bat 脚本,支持参数化配置并添加多重回退机制 - 优化开发服务器启动流程,提升不同环境下的兼容性
This commit is contained in:
60
start.bat
60
start.bat
@@ -1 +1,59 @@
|
||||
npm run docs:dev -- --host 0.0.0.0
|
||||
@echo off
|
||||
setlocal ENABLEDELAYEDEXPANSION
|
||||
|
||||
REM Usage:
|
||||
REM start.bat [host] [port]
|
||||
REM Examples:
|
||||
REM start.bat -> try 0.0.0.0:4567, fallback to localhost and 5173
|
||||
REM start.bat local 8080 -> localhost:8080
|
||||
REM start.bat lan 4567 -> 0.0.0.0:4567
|
||||
|
||||
set HOST=%~1
|
||||
if "%HOST%"=="" set HOST=0.0.0.0
|
||||
if /I "%HOST%"=="lan" set HOST=0.0.0.0
|
||||
if /I "%HOST%"=="local" set HOST=localhost
|
||||
|
||||
set PORT=%~2
|
||||
if "%PORT%"=="" set PORT=4567
|
||||
set FALLBACK_PORT=5173
|
||||
|
||||
echo [Start] VuePress dev on host %HOST% port %PORT%
|
||||
call npx vuepress@2.0.0-rc.24 dev docs --host %HOST% --port %PORT%
|
||||
if %ERRORLEVEL% EQU 0 goto success
|
||||
|
||||
REM Fallback 1: switch to localhost same port
|
||||
if NOT "%HOST%"=="localhost" (
|
||||
echo [Fallback] switch to localhost on same port %PORT%...
|
||||
call npx vuepress@2.0.0-rc.24 dev docs --host localhost --port %PORT%
|
||||
if %ERRORLEVEL% EQU 0 goto success
|
||||
)
|
||||
|
||||
REM Fallback 2: clean cache and use localhost on fallback port
|
||||
if NOT "%PORT%"=="%FALLBACK_PORT%" (
|
||||
echo [Fallback] clean cache and start on localhost:%FALLBACK_PORT%...
|
||||
call npx vuepress@2.0.0-rc.24 dev docs --clean-cache --clean-temp --host localhost --port %FALLBACK_PORT%
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
set HOST=localhost
|
||||
set PORT=%FALLBACK_PORT%
|
||||
goto success
|
||||
)
|
||||
)
|
||||
|
||||
REM Fallback 3: try another common port
|
||||
set ALT_PORT=8080
|
||||
if NOT "%PORT%"=="%ALT_PORT%" (
|
||||
echo [Fallback] try localhost:%ALT_PORT%...
|
||||
call npx vuepress@2.0.0-rc.24 dev docs --host localhost --port %ALT_PORT%
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
set HOST=localhost
|
||||
set PORT=%ALT_PORT%
|
||||
goto success
|
||||
)
|
||||
)
|
||||
|
||||
echo [Error] Failed to start dev server. Please check firewall or port usage.
|
||||
exit /b 1
|
||||
|
||||
:success
|
||||
echo [Ready] Open http://localhost:%PORT%/ (or http://%HOST%:%PORT%/ if accessible)
|
||||
exit /b 0
|
||||
Reference in New Issue
Block a user