#angular #docker #kubernetes #server-side-rendering #angular-universal
Вопрос:
Привет, я использую Angular 12 с универсальным (рендеринг на стороне сервера). Подробная информация об используемых пакетах добавлена ниже
Пакет.json
{
"name": "angular-starter",
"version": "3.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --port 4200",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"dev:ssr": "ng run angular-starter:serve-ssr",
"serve:ssr": "node dist/angular-starter/server/main.js",
"build:ssr": "ng build amp;amp; ng run angular-starter:server",
"prerender": "ng run angular-starter:prerender"
},
"author": {
"name": "Sharath",
"url": "http://sharath.fconsole.com/"
},
"private": true,
"dependencies": {
"@angular/animations": "12.1.1",
"@angular/cdk": "^12.1.3",
"@angular/common": "12.1.1",
"@angular/compiler": "12.1.1",
"@angular/core": "12.1.1",
"@angular/forms": "12.1.1",
"@angular/platform-browser": "12.1.1",
"@angular/platform-browser-dynamic": "12.1.1",
"@angular/platform-server": "12.1.1",
"@angular/router": "12.1.1",
"@angular/service-worker": "12.1.1",
"@fortawesome/fontawesome-free": "5.15.3",
"@nguniversal/express-engine": "12.1.0",
"bootstrap": "5.0.2",
"compression": "^1.7.4",
"express": "4.17.1",
"jquery": "^3.6.0",
"localstorage-polyfill": "^1.0.1",
"ng-pick-datetime": "^7.0.0",
"ngx-bootstrap": "^7.1.0",
"ngx-material-timepicker": "^5.5.3",
"ngx-pagination": "^5.1.1",
"ngx-slick-carousel": "^0.5.1",
"ngx-toastr": "^14.0.0",
"pm2": "^5.1.0",
"rxjs": "^6.6.7",
"rxjs-compat": "^6.6.7",
"tslib": "2.3.0",
"xml2js": "^0.4.23",
"zone.js": "0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "12.1.1",
"@angular/cli": "12.1.1",
"@angular/compiler-cli": "12.1.1",
"@nguniversal/builders": "12.1.0",
"@types/express": "4.17.12",
"@types/jasmine": "3.7.7",
"@types/node": "16.0.0",
"jasmine-core": "3.8.0",
"karma": "6.3.4",
"karma-chrome-launcher": "3.1.0",
"karma-coverage": "2.0.3",
"karma-jasmine": "4.0.1",
"karma-jasmine-html-reporter": "1.6.0",
"typescript": "4.2.4"
}
}
Угловой.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-starter": {
"projectType": "application",
"schematics": {
"@schematics/angular:application": {
"strict": true,
"changeDetection": "OnPush"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/angular-starter/browser",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets",
"src/manifest.webmanifest",
"src/sitemap.xml",
"src/robots.txt"
],
"styles": [
// "src/styles.css",
// "node_modules/@fortawesome/fontawesome-free/css/all.min.css",
// "node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/assets/params/css/navbar.css",
// "src/assets/css/colors/theme-skin-orange.css",
"src/assets/css/colors/theme-skin-orange1.css",
// "src/assets/css/menuzord-skins/menuzord-border-boxed.css",
// "src/assets/css/menuzord-skins/menuzord-border-bottom.css",
// "src/assets/css/menuzord-skins/menuzord-border-left.css",
// "src/assets/css/menuzord-skins/menuzord-border-top-bottom.css",
// "src/assets/css/menuzord-skins/menuzord-border-top.css",
// "src/assets/css/menuzord-skins/menuzord-bottom-trace.css",
// "src/assets/css/menuzord-skins/menuzord-boxed.css",
// "src/assets/css/menuzord-skins/menuzord-colored.css",
// "src/assets/css/menuzord-skins/menuzord-dark.css",
// "src/assets/css/menuzord-skins/menuzord-gradient.css",
"src/assets/css/menuzord-skins/menuzord-rounded-boxed.css",
// "src/assets/css/menuzord-skins/menuzord-shadow.css",
// "src/assets/css/menuzord-skins/menuzord-strip.css",
// "src/assets/css/menuzord-skins/menuzord-subcolored.css",
// "src/assets/css/menuzord-skins/menuzord-top-bottom-boxed-border.css",
// "node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/assets/css/flaticon-set-medical.css",
"src/assets/css/css-plugin-collections.css",
"src/assets/css/custom-bootstrap-margin-padding.css",
"src/assets/css/style-main.css",
"src/assets/css/animate.css",
"src/assets/css/bootstrap.min.css",
"src/assets/css/font-awesome/css/font-awesome.min.css",
],
"scripts": [
// "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js",
// "node_modules/bootstrap/dist/js/bootstrap.min.js",
//"node_modules/jquery/dist/jquery.min.js",
"src/assets/js/jquery-2.2.4.min.js",
"src/assets/js/bootstrap.min.js",
// "src/assets/js/custom.js",
"src/assets/js/calendar-events-data.js",
// "src/assets/js/jquery-plugin-collection.js",
// "src/assets/js/jquery-ui.min.js",
"src/assets/js/amcharts.js"
],
"serviceWorker": false,
"ngswConfigPath": "ngsw-config.json"
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "750kb",
"maximumError": "2.75mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "5kb",
"maximumError": "10kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all",
"sourceMap": false,
"namedChunks": true,
"buildOptimizer": true,
"optimization": {
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": false
},
"fonts": true
},
// "optimization": {
// "scripts": true,
// "styles": {
// "minify": true,
// "inlineCritical": false
// },
// "fonts": true
// }
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "angular-starter:build:production"
},
"development": {
"browserTarget": "angular-starter:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular-starter:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets",
"src/manifest.webmanifest"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/angular-starter/server",
"main": "server.ts",
"tsConfig": "tsconfig.server.json"
},
"configurations": {
"production": {
"outputHashing": "media",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
},
"development": {
"optimization": false,
"sourceMap": true,
"extractLicenses": false
}
},
"defaultConfiguration": "production"
},
"serve-ssr": {
"builder": "@nguniversal/builders:ssr-dev-server",
"configurations": {
"development": {
"browserTarget": "angular-starter:build:development",
"serverTarget": "angular-starter:server:development"
},
"production": {
"browserTarget": "angular-starter:build:production",
"serverTarget": "angular-starter:server:production"
}
},
"defaultConfiguration": "development"
},
"prerender": {
"builder": "@nguniversal/builders:prerender",
"options": {
"routes": [
"/"
]
},
"configurations": {
"production": {
"browserTarget": "angular-starter:build:production"
},
"development": {
"browserTarget": "angular-starter:build:development"
}
},
"defaultConfiguration": "production"
}
}
}
},
"defaultProject": "angular-starter"
}
Dockerfile
FROM node:14
# FROM keymetrics/pm2:14-alpine
LABEL maintainer "Sharath Jackey <itsmysignature007@gmail.com>"
# Install npm stuff.
RUN mkdir /api
WORKDIR /api
ADD package.json .
RUN npm install
# RUN npm install pm2 -g
# Bundle APP files
WORKDIR /api
ADD . .
RUN npm run build:ssr
# EXPOSE 4000/tcp
# Show current folder structure in logs
RUN ls -alh /api
RUN sed -i 's/<script src="/<link rel="preload" as="script" href="/g' dist/angular-starter/browser/index.html
RUN sed -i "s/defer></script>/></link>/g" dist/angular-starter/browser/index.html
# CMD ["pm2-runtime","dist/angular-starter/server/main.js"]
CMD ["node","dist/angular-starter/server/main.js"]
События не запускаются при развертывании в Docker.
он отлично работает в «npm run start» и «npm run build:ssr amp;amp; npm run serve:ssr» локально
События не запускаются при развертывании в Docker.
События не запускаются при развертывании в Docker.
События не запускаются при развертывании в Docker.
События не запускаются при развертывании в Docker.