Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARNING in Exceeded maximum budget for SCSS FILE IN ANGULAR

angular error

IMPORTING BOOTSTRAP VARIABLE in scss file getting error WARNING in Exceeded maximum budget for B:/Angular-8/crats-shop/src/app/shared/components/sort/sort.component.scss. Budget 6 kB was not met by 136 kB with a total of 142 kB

like image 733
aishvarya Avatar asked Apr 19 '20 16:04

aishvarya


People also ask

How are the budgets enforced with the angular CLI?

The budgets will be automatically enforced on each build with the Angular CLI. Consider introducing budget monitoring as part of continuous integration (which can also be achieved with the Angular CLI).

Is the 6kb budget in angular met by 202kB?

Budget 6 kB was not met by 202 kB with a total of 208 kB. Most of this budget overflow is from importing ~@angular/material/theming. Is it ok to increase budgets in angular.json to ~2-500kB, what are the drawbacks of doing this?

What is the size limit for a JavaScript bundle in angular?

There's a budget for a JavaScript bundle called main. If the main bundle gets bigger than 170 KB, the Angular CLI will show a warning in the console when you build the app. If the main bundle gets bigger than 250 KB, the build will fail.

How do I add a budget to my angular app?

First thing to make sure is that we have @angular/cli: "1.7.0" installed in our local dependencies. After that we go to the .angular-cli.json file and, in the app configuration, section we add the "budgets": setting. Where we go from here depends on our specific needs, but here are some common scenarios that you might find useful for your case:


2 Answers

budget is a group of limits to certain values that affect site performance

Open angular.json file and find budgets keyword and increase value

"budgets": [
   {
      "type": "initial",
      "maximumWarning": "4mb", <===
      "maximumError": "5mb"
   },
   {
      "type": "anyComponentStyle",
      "maximumWarning": "150kb",
      "maximumError": "150kb"
   }
]
like image 172
mr. pc_coder Avatar answered Oct 21 '22 15:10

mr. pc_coder


Even though you can just bump up your limits, it's probably not what you want to do. The limits are there for a reason. You should try to avoid exceeding them in the first place if possible.

For me, the problem was I was importing my theme file (which was quite large) into my components' SCSS files.

@import "src/my-theme";

The only reason for that was that I needed to access my SCSS color variables within those files. It's a terrible idea to import any larger file in multiple of your styles only to access a few of your variables; your application will become huge and really slow to load.

If you only need access to your variables, I suggest this solution:

  1. in your theme file, make CSS variables like so: :root { --primary-color: #11dd11; }
  2. remove the import from your other SCSS files and use this to get your color instead: var(--primary-color)
like image 21
kozenka Avatar answered Oct 21 '22 15:10

kozenka