Tho*_*mes 0 .net-core angular-universal ssr angular angular7
我正在尝试使用dotnet核心创建一个Angular 7 SSR来托管它,默认模板使用angular 5,并且MS有文档来使SSR在其上运行(效果很好),我尝试通过命令行将其升级到angular 7并开始一个新的角度项目并实施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).
Run Code Online (Sandbox Code Playgroud)
在此之后(https://github.com/aspnet/Templating/issues/593),我对NG5 SSR(https://go.microsoft.com/fwlink/?linkid=864501)所做的更改是:
startup.cs
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.bundle.js";
Run Code Online (Sandbox Code Playgroud)
至
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.js";
Run Code Online (Sandbox Code Playgroud)
再次将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"
}
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在package.json脚本中更改build:ssr
"build:ssr": "ng build --configuration=production --project=ssr",
Run Code Online (Sandbox Code Playgroud)
正在运行代码-https: //github.com/TPJ11/DotnetNG7SSR
有人知道我在做什么错吗?感觉就像我一直在把头撞在墙上:(
正确,所以不确定是什么破坏了应用程序,但是我已经解决了。
1)创建一个新的.Net Core NG应用程序并删除ClientApp文件夹,然后通过名为ClientApp的CMD创建一个空白的angular 7应用程序 ng new ClientApp
2)遵循角度SSR设置指南,直到第3步。
3)安装aspnet-prerendering npm i aspnet-prerendering
4)交换步骤2c(main.server.ts)中的代码以使用Microsoft安装指南中的main.server.ts中的代码
5)打开angular.json
文件并更改outputPath
为构建以dist
和服务器outputPath
,以dist-server
6)打开package.json
并scripts
添加"build:ssr": "ng run ClientApp:server"
7)打开tsconfig.server.json
并tsconfig.app.json
更改types
为包含节点"types": ["node"]
8)打开Startup.cs并如Microsoft安装指南中所示添加
spa.UseSpaPrerendering(options =>
{
options.BootModulePath = $"{spa.Options.SourcePath}/dist-server/main.js";
options.BootModuleBuilder = env.IsDevelopment()
? new AngularCliBuilder(npmScript: "build:ssr")
: null;
options.ExcludeUrls = new[] { "/sockjs-node" };
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3014 次 |
最近记录: |