Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng build --prod is extremely slow

We have an Angular project, and we're trying to build it with --prod option.

The problem is, it took 33 hours!

To be honest, we're not that good with Angular, npm and all that, we're all beginners in this world.

All we know, is when we execute the ng build --prod command, we get stuck in here for hours:

11% building modules 9/11 modules 2 active …s\font-awesome\css\font-awesome.min.css

We tried removing the font-awesome.min.css from the angular.json file, well we get stuck in another CSS file, and it never ends. Even when we removed all the CSS files from the angular.json file, we get stuck here:

10% building modules 2/2 modules 0 active

Here are our versions:

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.7.5
@angular-devkit/build-angular      0.7.5
@angular-devkit/build-ng-packagr   0.7.5
@angular-devkit/build-optimizer    0.7.5
@angular-devkit/build-webpack      0.7.5
@angular-devkit/core               0.7.5
@angular-devkit/schematics         0.8.9
@angular/cdk                       6.4.7
@angular/cli                       6.2.9
@angular/material                  6.4.7
@ngtools/json-schema               1.1.0
@ngtools/webpack                   6.1.5
@schematics/angular                0.8.9
@schematics/update                 0.8.9
ng-packagr                         4.7.1
rxjs                               6.4.0
typescript                         2.9.2
webpack                            4.9.2

All we want, is to find a way to debug this problem, or maybe someone already experienced the same problem?

Here are my computed specs:

Processor: Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz 3.19 GHz
RAM: 32Gb
Windows 7
like image 707
user Avatar asked Feb 26 '19 15:02

user


People also ask

Why does ng serve take so long?

This is mostly because of bulky source map files. When you do ng serve , Angular serves the app from memory instead of the dist folder (the file system). This means the entire code (along with map files) will be loaded into the system's memory and this is the main reason why your system or IDE getting slow.

What is the difference between ng build and NPM run build?

If you run ng build directly, Ionic hooks won't be triggered as it is bypassed. npm run build picks the "build" from package. json which is the same as ng build . It is helpful for CI where you do not have ionic or ng commands available.


1 Answers

Increasing node's allotted memory size really sped things up for me. You can see here I gave it an entire 8GB as opposed to the default 512MB.

> node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod

If you are unsure of how much memory your machine has available use the following command to see memory stats based on MB, check under the available column not the free column.

> free -m
              total        used        free      shared  buff/cache   available
Mem:          15866        1490        3726         116       10650       13929
like image 82
kebab-case Avatar answered Oct 22 '22 11:10

kebab-case