在angular 项目中使用 npm run build
出现 * exceeded maximum budget
警告或错误
Warning or Error in exceeded maximum budget for scss file in Angular.
在 Angular 项目中使用 npm run build
or npm run build:prod
时,在命令行可能出现一下警告或错误:
主要的问题有:
- /Users/Documents/angular-basic-practice/src/app/app.component.scss exceeded maximum budget.
- Budget 4.00 kB was not met by 62.40 kB with a total of 66.40 kB.
一个是说明问题出现的主要点在哪里。另一个说说明问题出现的具体情况。
问题原因
那这里我们根据几个关键词很容易想到是 angular.json 中 budgets 配置 的问题。
在我们的 angular.json
文件中,目前是:
解决方式
简单的解决方式是将其设置的最大警告/最大报错值设置更大的值:
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2mb",
"maximumError": "4mb"
}
]
其他的解决方式需要从相关文件入手,避免出现大文件的情况。当然也需要考虑性能方面。就不再这里讨论了。