mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
Currently writing schematics that support both NgModule-based and standalone projects is tricky, because they have different layouts. These changes introduce two new APIs that work both on NgModule and standalone projects and can be used by library authors to create their `ng add` schematics. Example rule for adding a `ModuleWithProviders`-style library: ```ts import { Rule } from '@angular-devkit/schematics'; import { addRootImport } from '@schematics/angular/utility'; export default function(): Rule { return addRootImport('default', ({code, external}) => { return code`${external('MyModule', '@my/module')}.forRoot({})`; }); } ``` This rulle will add `imports: [MyModule.forRoot({})]` to an NgModule app and `providers: [importProvidersFrom(MyModule.forRoot({}))]` to a standalone one. It also adds all of the necessary imports.