Angular 6 CLI -> how to make ng build build project + libraries

前端 未结 9 572
感情败类
感情败类 2020-12-31 01:58

So the question is pretty basic but I can\'t find it.

I created a new app through ng new my-project, followed by a ng g library my-library.

9条回答
  •  抹茶落季
    2020-12-31 02:15

    "build-all": "for PROJ in lib1 lib ''; do ng build $PROJ --prod || break; done"
    
    • The '' provides an empty string to the loop, building the top-level project
    • The || break stops the for loop once a library build fails

    OR the follow works if

    • Build system has jq
    • None of your libraries have dependencies on each-other
      • This blindly builds over a list of projects found in angular.json
    • Use scoped packages for your libraries
      • Why would you not?!
      • See next bullet's reason
    • Top-level project is not scoped
      • Normally my top-level is a demo project, never published, so never scoped
      • Reason for this is jq always returns @ prefixed keys first in the array to loop over

    "build-all": "for PROJ in $(cat angular.json | jq -r '.projects | keys[]'); do ng build $PROJ --prod; done"
    

    At some point I want to look into building up a dependency tree based on the package.json(s) found in each project and sort the projects to build based on that. Just not a high priority over up-keeping a hard-coded list from the first suggestion :)

提交回复
热议问题