对于2GB大小的应用程序,npm run build需要太长时间

时间:2019-07-04 12:08:48

标签: node.js npm angular-cli package.json

我正在使用最新版本的angular项目。我正在尝试进行生产构建。完成需要4个多小时。我正在使用“ npm run build--c production” 命令进行构建。还有其他命令可以进行生产构建吗?请提供您宝贵的反馈意见。

package.json:

{
      "name": "sample",
      "version": "0.0.0",
      "license": "MIT",
      "scripts": {
        "ng": "ng",
        "start": "node --max_old_space_size=20480 ./node_modules/@angular/cli/bin/ng serve --aot",
        "serve": "node --max_old_space_size=20480 ./node_modules/@angular/cli/bin/ng serve",
        "build": "rimraf dist && node --max_old_space_size=20480 ./node_modules/@angular/cli/bin/ng build",
        "e2e": "ng e2e",
        "postbuild": "node zipbuild.js"
      },
      "private": true,
      "dependencies": {
        "@angular/animations": "8.0.3",
        "@angular/cdk": "8.0.1",
        "@angular/common": "8.0.3",
        "@angular/compiler": "8.0.3",
        "@angular/core": "8.0.3",
        "@angular/flex-layout": "^8.0.0-beta.26",
        "@angular/forms": "8.0.3",
        "@angular/material": "8.0.1",
        "@angular/platform-browser": "8.0.3",
        "@angular/platform-browser-dynamic": "8.0.3",
        "@angular/router": "8.0.3",
        "@aspnet/signalr": "1.1.4"
      },
      "devDependencies": {
        "@angular-devkit/build-angular": "~0.800.6",
        "@angular/cli": "8.0.6",
        "@angular/compiler-cli": "8.0.3",
        "@angular/language-service": "8.0.3",
        "@types/jasmine": "~3.3.13",
        "@types/jasminewd2": "~2.0.6",
        "@types/node": "12.0.10"
      }
    }

angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "test": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/test",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": true,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "test:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "test:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "test: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"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "test:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "test:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "test"
}

1 个答案:

答案 0 :(得分:-1)

其中一项改进的选项是,建议使用npm ci

最重要的是,您必须检入package-lock.json文件。 npm ci会直接跟随loke文件来安装所有软件包。这样可以节省依赖性检查时间,也可以使其保持一致。

另一种工具,请检查webpack