简体   繁体   中英

how to build spesific modules in angular 2+

I would like to know is there any way to build specific modules from an application which have multiple modules.

for example, I have module a,b and c in an application but for one of my client required only b and c. I don't want to compile all the modules and remove unwanted chunks looking for a way to compile chunks which only passed as a command or something.

any help highly appreciated.

You can use the router ability to lazy-load sub-modules in your application.

This will make separate JS chunks of your modules for your application.

Unfortunately, everything will be compiled, because you cannot delete links that easily in imports and such, but your module will not be downloaded nor resolved if your user doesn't go to these modules in your app.

Here is the official documentation link about this :

NB : In this example, the whole application with the base module is lazy-loaded and this is not a good practice. Only sub-modules that may not be reached are meant to be lazy-loaded.

Use the following structure.

By using CommonModule instead BrowserModule

import { CommonModule } from '@angular/common';
import { NgModule } from "@angular/core";

import { LastTableComponent } from './last-table.component';

@NgModule({
    imports: [
      CommonModule,          
    ],
    exports:[
      LastTableComponent,
    ],
    declarations: [
      LastTableComponent,
    ],
    providers: [     
    ]

  })
export class LastTableModule { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM