angular add universal
ng add @nguniversal/express-engine
angular universal
ng add @nguniversal/express-engine --clientProject <name-of-your-project>
npm run build:ssr
npm run serve:ssr
we need a server for server side rendering of angular
// Static Pre-Renderingnpm run build:prerender && npm run serve:prerender
server side rendering in agular
//first step:
ng add @nguniversal/express-engine
//second step:
npm run dev:ssr
//third step:
ng build && ng run app-name:server
//fourth step:
npm run serve:ssr
//fifth step:
npm run prerender
//sixth step:
npm run serve:ssr
//diff method:
ng add @nguniversal/express-engine
//angular.json file change:
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist-server",
"main": "server.ts",
"tsConfig": "tsconfig.server.json",
"inlineStyleLanguage": "scss"
},
//package.json file change:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"dev:ssr": "ng run test-universal:serve-ssr",
"serve:ssr": "node dist-server/main.js",
"build:ssr": "ng build && ng run test-universal:server",
"prerender": "ng run test-universal:prerender"
//run command:
ng run test-universal:server
ng run build:ssr
npm run serve:ssr
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us