简体   繁体   English

供应商捆绑包大小未减少

[英]Vendor Bundle Size Not Reducing

I'm trying to get my build much smaller to get my load time faster, but when I run我试图让我的构建更小以加快加载时间,但是当我运行时

ng build --prod --aot --vendor-chunk --common-chunk --build-optimizer and then run a lighthouse report from google dev tools ng build --prod --aot --vendor-chunk --common-chunk --build-optimizer然后从谷歌开发工具运行一个灯塔报告

I get我明白了

在此处输入图像描述

what's odd is that it seems to have worked if I go into the dist folder to look at file sizes, which seem smaller that the lighthouse report.奇怪的是,如果我将 go 放入 dist 文件夹以查看文件大小,它似乎有效,这似乎比灯塔报告的要小。

在此处输入图像描述

So far to reduce the size by doing the following:到目前为止,通过执行以下操作来减小大小:

  • Removed old/unused package.json entries删除了旧的/未使用的 package.json 条目
  • changed all material imports to specific path like for paginator I'm importing now as import { MatPaginator } from "@angular/material/paginator";将所有材料导入更改为特定路径,例如我现在导入的分页器作为import { MatPaginator } from "@angular/material/paginator"; instead of import { MatPaginator } from "@angular/material/";而不是import { MatPaginator } from "@angular/material/"; per the advice from other posts.根据其他帖子的建议。
  • replaced moment with moment.min.js so that locales don't get added用 moment.min.js 替换了 moment,这样就不会添加语言环境
  • added brotli for text compression.为文本压缩添加了 brotli。

Also I want to mention because I don't know if it's relevant, but I don't have a webpack.config.js file only a custom-webpack.config.js for brotli.另外我想提一下,因为我不知道它是否相关,但我没有webpack.config.js文件,只有一个用于 brotli 的custom-webpack.config.js webpack.config.js。 The only thing I edited in angular.json to get webpack working was this for brotli我在 angular.json 中编辑的唯一让 webpack 工作的东西是用于 brotli

  "architect": {
        "build": {
          "builder": "@angular-builders/custom-webpack:browser",
          "options": {
            "customWebpackConfig": {
              "path": "./custom-webpack.config.js"
             },

I've never used webpack before so this could be an issue, but I'm not sure.我以前从未使用过 webpack,所以这可能是个问题,但我不确定。

package.json package.json

{
  "name": "mean-course",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "webpack-dev-server --mode development --open",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "start:server": "nodemon backend/server.js"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.13",
    "@angular/cdk": "~8.2.2",
    "@angular/common": "~8.2.4",
    "@angular/compiler": "~8.2.4",
    "@angular/core": "~8.2.4",
    "@angular/forms": "~8.2.4",
    "@angular/material": "^8.2.2",
    "@angular/platform-browser": "~8.2.4",
    "@angular/platform-browser-dynamic": "~8.2.4",
    "@angular/router": "~8.2.4",
    "@ng-bootstrap/ng-bootstrap": "^5.1.5",
    "@ngrx/store": "^8.6.0",
    "ably": "^1.1.22",
    "angular-doka": "file:src/angular-doka",
    "angular-filepond": "^1.0.5",
    "azure-arm-rediscache": "^3.0.0",
    "bootstrap": "^4.4.1",
    "classlist.js": "^1.1.20150312",
    "countdown": "^2.6.0",
    "dotenv": "^8.2.0",
    "filepond": "^4.13.4",
    "filepond-plugin-file-encode": "^2.1.5",
    "filepond-plugin-file-validate-size": "^2.2.0",
    "filepond-plugin-file-validate-type": "^1.2.5",
    "filepond-plugin-image-crop": "^2.0.3",
    "filepond-plugin-image-edit": "^1.6.0",
    "filepond-plugin-image-exif-orientation": "^1.0.7",
    "filepond-plugin-image-preview": "^4.6.1",
    "filepond-plugin-image-resize": "^2.0.4",
    "filepond-plugin-image-transform": "^3.7.2",
    "jquery": "^3.5.1",
    "jsonwebtoken": "^8.5.1",
    "lib-storage-service": "^1.0.2",
    "material": "^0.4.1",
    "moment-mini": "^2.24.0",
    "ng-starrating": "^1.0.20",
    "ngx-bar-rating": "^1.1.0",
    "ngx-clipboard": "^12.3.0",
    "ngx-device-detector": "^1.3.20",
    "ngx-filepond": "^5.0.1",
    "ngx-light-carousel": "^1.0.37-beta.8",
    "ngx-pagination": "^5.0.0",
    "ngx-simple-countdown": "^1.0.2",
    "ngx-spinner": "^8.0.3",
    "ngx-toastr": "^11.2.1",
    "ngx-ui-carousel": "^1.3.2",
    "numeral": "^2.0.6",
    "rxjs": "~6.4.0",
    "tslib": "^1.10.0",
    "tsoa": "^2.5.7",
    "uid": "0.0.2",
    "web-animations-js": "^2.3.2",
    "yamljs": "^0.3.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "8.4.1",
    "@angular-devkit/build-angular": "^0.803.26",
    "@angular/cli": "~8.3.2",
    "@angular/compiler-cli": "~8.2.4",
    "@angular/language-service": "~8.2.4",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^8.10.59",
    "brotli-gzip-webpack-plugin": "^0.5.0",
    "brotli-webpack-plugin": "^1.1.0",
    "codelyzer": "^5.0.0",
    "compression-webpack-plugin": "^4.0.0",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3"
  },
  "browser": {
    "crypto": false
  }
}

Here is a stats.json file when using ng build --prod这是使用ng build --prod时的 stats.json 文件

在此处输入图像描述

Here's a more detailed version as well这里还有一个更详细的版本

在此处输入图像描述

Remove libraries like ngx-spinner, filepond etc. which are huge as they are not treeshakable.删除 ngx-spinner、filepond 等库,因为它们不可摇动,所以它们很大。 Also if you have not configured your server to serve gzip files, do that.此外,如果您尚未将服务器配置为提供 gzip 文件,请执行此操作。 It will give you huge reduction in size.它会给你很大的尺寸减小。 Also pre gzip your js files after build my using a utility like gzip-all.在使用 gzip-all 之类的实用程序构建我之后,还要预先 gzip 你的 js 文件。

https://www.npmjs.com/package/gzip-all https://www.npmjs.com/package/gzip-all

Also change your server max cache policy to get caching benefits.还要更改您的服务器最大缓存策略以获得缓存优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM