14

我正在使用节点版本 8.9.4,npm 版本 5.6.0 我不知道为什么会发生这种情况, ng build --dev正在生成 vendor.bundle.js 而ng build --prod没有生成 vendor.bundle.js 这是屏幕截图

使用 ng build--prod输出 [ 在此处输入图像描述
[使用 ng-build --dev 输出] 在此处输入图像描述

这是我的 package.json

`{
  "name": "app1",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/core": "0.0.28",
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.6.3",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

`

4

2 回答 2

33

对于 prod 构建,供应商捆绑包集成在您的主捆绑包中,因为它默认使用构建优化器。

根据angular-cli 文档

如果没有单独的供应商块,则构建优化器的总包大小会更小,因为供应商代码与应用程序代码位于同一块中,这使得 Uglify 可以删除更多未使用的代码。

于 2018-01-21T16:33:37.220 回答
17

ng build 默认情况下不生成供应商块,而是将其组合在一个主块中以实现性能和优化目的,您需要像这样向构建命令添加一个参数,以便分离供应商块:
ng build --prod --vendor-chunk=true

在此处查看详细信息:

https://github.com/angular/angular-cli/wiki/build#--build-optimizer-and---vendor-chunk

于 2018-01-21T16:34:57.500 回答