我正在运行一个在我的 Angular 13 项目上构建预渲染版本的命令:
“prerender:staging”:“ng run app:prerender --configuration staging”,
这是我的 angular.json :
"prerender": {
"builder": "@nguniversal/builders:prerender",
"options": {
"guessRoutes": false,
"routes": [
"/"
]
},
"configurations": {
"staging": {
"browserTarget": "app:build:staging",
"serverTarget": "app:server:staging"
},
},
"defaultConfiguration": "staging"
},
在暂存配置“outputHashing”时构建此命令时:“none” - 一切都很好并且工作正常。
当我将
"outputHashing": "none"
更改为 "outputHashing": "all"
时,我在预渲染构建结束时收到此错误:
An unhandled exception occurred: Could not find the main bundle: C:\Users\andri\OneDrive\Desktop\test\TEST-Project\app\dist\app\server\main.js
See "C:\Users\user\AppData\Local\Temp\ng-HwSKT5\angular-errors.log" for further details.
如何使用 outputHashing="all" 构建 Angular 预渲染?这很重要,因为它会在每个新版本部署到服务器后消除缓存。
实际上,您仅需要浏览器捆绑包(和媒体)而不是服务器捆绑包的outputHashing。这就是为什么服务器目标的默认配置是
outputHashing: 'media'
。我通常将其设置为 none
以避免预渲染期间与媒体相关的异常。