当使用--prod构建我的angular 7项目时,我在预算中发出警告。

我有一个angular 7项目,我想构建它,但有一个警告:

WARNING in budgets, maximum exceeded for initial. Budget 2 MB was exceeded by 1.77 MB

这些是块详细信息:
chunk {scripts} scripts.2cc9101aa9ed72da1ec4.js (scripts) 154 kB  [rendered]
chunk {0} runtime.ec2944dd8b20ec099bf3.js (runtime) 1.41 kB [entry] [rendered]
chunk {1} main.13d1eb792af7c2f359ed.js (main) 3.34 MB [initial] [rendered]
chunk {2} polyfills.11b1e0c77d01e41acbba.js (polyfills) 58.2 kB [initial] [rendered]
chunk {3} styles.33b11ad61bf10bb992bb.css (styles) 379 kB [initial] [rendered]

预算到底是什么?我应该如何管理它们?

最佳答案

打开 angular.json 文件,然后找到budgets关键字。
它应该看起来像:

    "budgets": [
       {
          "type": "initial",
          "maximumWarning": "2mb",
          "maximumError": "5mb"
       }
    ]
您可能已经猜到了可以增加maximumWarning值来防止出现此警告,即:
    "budgets": [
       {
          "type": "initial",
          "maximumWarning": "4mb", <===
          "maximumError": "5mb"
       }
    ]
预算是什么意思?

在我们的情况下,预算是 bundle 商品大小的限制。
也可以看看:
  • https://github.com/webpack/webpack/issues/3216
  • https://angular.io/guide/build#configure-size-budgets
  • Performance Budgets (Keep Request Counts Low And File Sizes Small)
  • 关于angular - 预算警告,初始预算超出上限,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53995948/

    10-12 06:10