我正在尝试使用dotnet core托管Angular 7 SSR,而默认模板使用的是Angular 5,并且微软有相关文档可以让SSR在Angular 5上运行(这个也能正常工作)。我尝试通过命令行升级到Angular 7并启动一个新的Angular项目并实现SSR,但我总是遇到同样的问题。从命令行中,ng build和ng build:SSR都能正常工作,但当我在VS中运行时,会超时(我认为这与问题无关),然后抛出以下错误:
The thread 0x6608 has exited with code 0 (0x0).
The thread 0x1134 has exited with code 0 (0x0).
The thread 0x54bc has exited with code 0 (0x0).
我从NG5 SSR (https://go.microsoft.com/fwlink/?linkid=864501) 开始做了一些改变,参考了这个(https://github.com/aspnet/Templating/issues/593),具体如下:
startup.cs
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.bundle.js";
到
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.js";
将SSR项目重新添加到 angular.json 中
"ssr": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist-server",
"main": "src/main.server.ts",
"tsConfig": "src/tsconfig.server.json"
},
"configurations": {
"production": {
"optimization": false,
"outputHashing": "media",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"bundleDependencies": "all",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
}
}
}
在package.json脚本中更改build:ssr
"build:ssr": "ng build --configuration=production --project=ssr",
我正在运行的代码 - https://github.com/TPJ11/DotnetNG7SSR
有人知道我做错了什么吗?感觉我一直在这个问题上碰壁 :(