Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

273
Views
Angular 2 building single modules

I know how to build out my project with Angular CLI: ng build --prod

How can I compile each module separately? This is my project:

Image

AnagAccreditamento and cruscottofiliera are separate modules, with their module.ts, routing.module.ts file. How I can build them separately and insert them into my project at a later time as if they were libraries?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Not sure about angular2 but you 'could'(!) definitely do this with angular 10. Not sure if it's the right way to do it (or if further separation would be a good idea).

To achieve building multiple modules out of a single project:

  1. You obviously need multiple modules. So not only app.module.tsbut another one that contains similar model configuration stuff, i.e. called app-extension.module.ts.

  2. Accordingly you'll need another main.ts file, referencing the module. I.e. called main-extension.ts. You import the specific module there and bootstrap it.

  3. Same for tsconfig.app.json -> tsconfig.app-extension.json

  4. Next, in your angular.json file, you can extend the project -> architect -> build section by adding something like this:

       "configurations": {
         "extension": {
           "main": "src/main-extension.ts",
           "tsConfig": "tsconfig.app-extension.json",
           "outputPath": "../resources/public/extension"
         }
    
  5. finally within your package.json you add a new script

         "build:extension": "ng build && ng build --output-hashing none --configuration extension "
    

    the --output-hashing none is not really relevant here. I did this for building a custom elements-module / webcomponents for standalone use, so that's why i left it in here. Next step would be to concatenate. A better alternative probably is to use https://github.com/manfredsteyer/ngx-build-plus#readme for that purpose..

to build simply execute npm run build:extension

about 4 years ago · Santiago Trujillo Report

0

If you want to be able to pull in modules as they are needed, you want lazy loading. You can find out how to use lazy loading here: https://angular.io/docs/ts/latest/guide/router.html#!#asynchronous-routing

Or there is a Pluralsight course about it here: https://app.pluralsight.com/library/courses/angular-routing/table-of-contents

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!