構建的錯誤信息如下:
09:52:57.975 ? YN0000: · Done with warnings in 3s 120ms
09:52:58.072 Executing user command: npm run build
09:52:58.817 npm ERR! Missing script: "build"
09:52:58.818 npm ERR!
09:52:58.818 npm ERR! To see a list of scripts, run:
09:52:58.818 npm ERR! npm run
09:52:58.818
09:52:58.819 npm ERR! A complete log of this run can be found in: /opt/buildhome/.npm/_logs/2025-04-10T13_52_58_752Z-debug-0.log
09:52:58.825 Failed: Error while executing user command. Exited with error code: 1
問題和解決
上面的問題是在執行構建的時候 VitePress 的構建命令不是 npm run build。
這個構建命令需要改成:npm run docs:build
在 cloudflare page 中選擇構建配置。
然后單擊編輯按鈕, 有 2 個地方要修改。
一個是構建的命令,一個是構建完成后輸出文件夾的路徑。
如果dist 文件夾的路徑不修改,后面會提示部署找不到需要部署的文件。
https://www.isharkfly.com/t/vitepress-cloudflare-page-npm-run-build/17166https://www.isharkfly.com/t/vitepress-cloudflare-page-npm-run-build/17166