Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Beyond ng new

Beyond ng new

Use lesser known features of the Angular CLI to unlock the ultimate productivity

Ciro Nunes

June 22, 2018
Tweet

More Decks by Ciro Nunes

Other Decks in Programming

Transcript

  1. ng new gdg-devfest --routing --prefix gdg Start new projects Include

    routing module and prefix all components with gdg-
  2. ng add @angular/material Add libraries Install the official material packages

    and schematics to generate material components ng g @angular/material:dashboard --name my-dash
  3. ng add @angular/material Add libraries Install the official material packages

    and schematics to generate material components ng g @angular/material:dashboard --name my-dash Generate the dashboard component using @angular/material schematics
  4. ng update --all --next -d Update packages ( All packages

    to latest versions including betas and RCS
  5. Create libraries for your components Pro tip! It’s a good

    way to check if their APIs are well designed
  6. z import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; export

    function myComponent(options: any): Rule { return (tree: Tree, _context: SchematicContext) => { return tree; }; }
  7. z import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; export

    function myComponent(options: any): Rule { return (tree: Tree, _context: SchematicContext) => { return tree; }; }
  8. z import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; export

    function myComponent(options: any): Rule { return (tree: Tree, _context: SchematicContext) => { tree.create(options.name || 'hello', 'world'); return tree; }; } Create and modify files
  9. z import { Rule, SchematicContext, Tree, chain, externalSchematic } from

    '@angular-devkit/schematics'; export function myComponent(options: any): Rule { return (tree: Tree, _context: SchematicContext) => { tree.create(options.name || 'hello', 'world'); return chain(tree, externalSchematic(...)); }; } Chain external schematics
  10. z { "$schema": “.../@angular-devkit/schematics/ collection-schema.json", "schematics": { "my-component": { "description":

    "A blank schematic.", "factory": "./my-component/index#myComponent" } } } Schematics collection collection.json
  11. ng new myapp Use it with the CLI npm link

    $PATH_TO_my-component ng g my-component:my-component someName
  12. / Practice the commands, use dry runs 0 Use, create

    and share schematics 1 Use the help command and the docs Takeaways 2 Embrace the ecosystem