How to speed up the Angular build process

前端 未结 6 1809
予麋鹿
予麋鹿 2020-12-23 11:17

After making some changes in my TypeScript files, each build takes over 20 minutes. I run this command: ng build --output-path=..\\..\\static\\angularjs.

<
相关标签:
6条回答
  • 2020-12-23 11:45

    This reduced my build time to 50%

    "optimization": false,
    "outputHashing": "none",
    "sourceMap": false,
    "extractCss": true,
    "namedChunks": false,
    "showCircularDependencies": false,
    "aot": true,
    "extractLicenses": false,
    "statsJson": false,
    "progress": false,
    "vendorChunk": true,
    "buildOptimizer": false,
    
    0 讨论(0)
  • 2020-12-23 11:47

    You can use node parameter --max_old_space_size like

    node --max_old_space_size=4096 ./node_modules/.bin/ngbuild --prod --build-optimizer
    

    But I prefer to set it up via environment:

    NODE_OPTIONS=--max-old-space-size=4096
    

    It speedup our build process on CI pipeline twice.

    0 讨论(0)
  • 2020-12-23 11:56

    According to https://github.com/angular/angular-cli/issues/6795 using --build-optimizer=false speeds up the build.

    0 讨论(0)
  • 2020-12-23 11:59

    My app took 28secs to build, but I've reduced the time to 9secs. Usings this flag

    ng build --source-map=false
    

    you can see the difference in time comparing the time:

    ng build --stats-json 
    
    ng build --stats-json --source-map=false
    

    source map is intended only for debugging, Hope it helps

    0 讨论(0)
  • 2020-12-23 12:02

    While in dev mode you can change this flag for your development to

    "buildOptimizer": false
    

    This worked for me . Angular 7 .

    0 讨论(0)
  • 2020-12-23 12:07

    I've found that for me, this issue was solved by using the watch flag, i.e.

    ng build --watch=true
    

    This runs constantly, and automatically builds files only when saved. It has dropped my build time from 8 sec to <1 sec for small changes in code, since it only generates .js files for what actually changed.

    From https://angular.io/guide/deployment

    The ng build command generates output files just once and does not serve them.

    The ng build --watch command will regenerate output files when source files change. This --watch flag is useful if you're building during development and are automatically re-deploying changes to another server.

    You should probably use ng build with the necessary options when you are building for production so that the necessary optimizations are completed.

    0 讨论(0)
提交回复
热议问题