ng 服务端渲染

时间:2022-05-22 21:12:50

官网文档

教学视屏

ng-toolkit

@ng-toolkit/universal

注意:

  • 使用 npm和yarn安装项目依赖,不要使用cnpm
  • ng add @ng-toolkit/universal 成功后可能需要安装 @angular/http 依赖
  • npm run build:prod 失败,尝试更新 webpack-cli 到 3.1.0 版本
  • 打包成功后执行 npm run server,在访问 http://localhost:8080 查看源码

当前环境:

λ ng v

     _                      _                 ____ _     ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/ Angular CLI: 7.3.0
Node: 10.15.0
OS: win32 x64
Angular: 7.2.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser-dynamic, router Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.13.0
@angular-devkit/build-angular 0.13.0
@angular-devkit/build-optimizer 0.13.0
@angular-devkit/build-webpack 0.13.0
@angular-devkit/core 7.3.0
@angular-devkit/schematics 7.0.7
@angular/cli 7.3.0
@angular/platform-browser 6.1.10
@angular/platform-server 6.1.10
@ngtools/webpack 7.3.0
@schematics/angular 7.0.7
@schematics/update 0.13.0
rxjs 6.3.3
typescript 3.2.4
webpack 4.29.0