我有环境:
- 詹金斯
- Docker
- proxmox 与 vm 和 lxc 容器
- 角度 9 项目
问题在于我的 Dockerfile 构建,大约需要 35-40 分钟。
我的 dockerfile
FROM node:12.6-stretch
ARG ABSOLUTE_PATH=./app
ARG build_command="node --max_old_space_size=5120 node_modules/@angular/cli/bin/ng build"
COPY $ABSOLUTE_PATH/package.json /app/package.json
COPY $ABSOLUTE_PATH/.npmrc /app/.npmrc
WORKDIR /app
RUN npm i
RUN node node_modules/@angular/cli/bin/ng version
COPY $ABSOLUTE_PATH/. ./
RUN npm run build-dependency
RUN npm run ${build_command}
我使用的是 proxmox,其中有 lxc 容器和 vm,但在这两种情况下,构建项目的时间是相同的。虚拟机有 12GB RAM 和 12 个核心。
我也在拥有 32GB RAM、Ryzen 5 的电脑上尝试过,但构建时间也很长,仅在海平面以上就需要 10 多分钟。
我的角度项目依赖项
"dependencies": {
"@angular/animations": "10.1.4",
"@angular/cdk": "10.2.3",
"@angular/common": "10.1.4",
"@angular/compiler": "10.1.4",
"@angular/core": "10.1.4",
"@angular/forms": "10.1.4",
"@angular/http": "7.2.16",
"@angular/material": "10.2.3",
"@angular/material-moment-adapter": "10.2.3",
"@angular/platform-browser": "10.1.4",
"@angular/platform-browser-dynamic": "10.1.4",
"@angular/router": "10.1.4",
"@angular/service-worker": "10.1.4",
"@ngrx/effects": "10.0.0",
"@ngrx/store": "10.0.0",
"@ngrx/store-devtools": "10.0.0",
"@turf/turf": "5.1.6",
"@types/jszip": "3.4.1",
"@types/jwt-decode": "2.2.1",
"@types/lodash": "4.14.159",
"angular-oauth2-oidc": "9.2.2",
"angular-oauth2-oidc-jwks": "9.0.0",
"angular-resize-event": "1.2.2",
"apexcharts": "3.20.0",
"axios": "0.19.2",
"bootstrap": "4.1.3",
"core-js": "3.6.5",
"highlight.js": "9.18.3",
"jszip": "3.5.0",
"jwt-decode": "^2.2.0",
"lodash": "4.17.20",
"material-design-icons": "^3.0.1",
"mathjs": "9.2.0",
"moment": "2.27.0",
"ng-apexcharts": "1.5.1",
"ngx-image-cropper": "1.5.1",
"ngx-quill": "12.0.1",
"normalizr": "^3.6.0",
"ol": "5.3.3",
"proj4": "2.6.2",
"quill": "1.3.7",
"rxjs": "6.6.3",
"tslib": "2.0.1",
"tui-calendar": "1.12.13",
"zone.js": "0.10.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.1001.4",
"@angular-devkit/build-ng-packagr": "0.1001.4",
"@angular/cli": "10.1.4",
"@angular/compiler-cli": "10.1.4",
"@angular/language-service": "10.1.4",
"@types/jasmine": "^3.3.16",
"@types/jasminewd2": "^2.0.8",
"@types/node": "^12.12.54",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~3.3.0",
"karma-jasmine-html-reporter": "^1.5.0",
"ng-packagr": "^10.0.0",
"node-sass": "^4.14.1",
"protractor": "~7.0.0",
"ts-node": "8.3.0",
"tslint": "6.1.3",
"typescript": "3.9.7"
}
我在这里没有看到任何可以延长软件包安装和项目构建时间的东西。也许你知道问题出在哪里?
答案1
我找到了解决办法:)
问题出在构建配置上,我到处都打开了优化,我将 angular.json 中的配置更改为“
optimization": false,
"outputHashing": "none",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"showCircularDependencies": false,
"aot": true,
"statsJson": false,
"progress": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": false,
"serviceWorker": true,
现在它构建得非常快:)