Slide 1

Slide 1 text

Managing Monorepos with Nx - Nrwl/Nxの近況 - ng-japan OnAir #12

Slide 2

Slide 2 text

Noriyuki Shinpuku ng-fukuoka organizer VEGA corporation Co., Ltd. @puku0x 2

Slide 3

Slide 3 text

Monorepo? Nx? 3

Slide 4

Slide 4 text

Monorepo ● A single repository containing multiple projects ○ Monorepo !== Monolith ● Used by 4 ...

Slide 5

Slide 5 text

5 https://nx.dev/

Slide 6

Slide 6 text

Nx ● Developed by Nrwl ● Monorepo management tool ○ Modern web development ○ Effective change detection ○ Automated migration 6 “Develop like Google, Facebook and Microsoft”

Slide 7

Slide 7 text

Version histories ● v1.x〜(April, 2018) ○ Extensions for Angular CLI ● v6.x ○ Jest support ● v7.x ○ Cypress and Nest support ● v8.x ○ React, Next.js and Storybook support ● v9.x ○ Angular v9 support 7

Slide 8

Slide 8 text

$ npx create-nx-workspace : ? Workspace name (e.g., org name) workspace ? What to create in the new workspace angular-nest ? Application name web ? Default stylesheet format SASS(.scss) Creating a workspace 8

Slide 9

Slide 9 text

Nx workspace ● Similar to Angular workspace ● Single version policy ○ package.json is a single source of truth 9

Slide 10

Slide 10 text

Scaffolding ● Applications ○ nx g @nrwl/angular:app ● Libraries ○ nx g @nrwl/angular:lib ● Schematics ○ nx g workspace-schematic 10

Slide 11

Slide 11 text

Testing ● Jest ○ nx test ● Cypress ○ nx e2e 11

Slide 12

Slide 12 text

$ npm i -D @nrwl/storybook $ npm i -D @storybook/angular @storybook/addon-knobs $ nx g @nrwl/angular:storybook-configuration # Run storybook $ nx run project-name:storybook # E2E with Cypress $ nx e2e project-name-e2e Storybook 12

Slide 13

Slide 13 text

Linting/Formatting ● ESLint/TSLint ○ nx lint ○ nx workspace-lint ● Prettier ○ nx format:write ○ '--uncommitted' option for lint-staged 13

Slide 14

Slide 14 text

enforce-module-boundaries ● Dependency constraints https://nx.dev/web/guides/monorepo-tags 14

Slide 15

Slide 15 text

Dependency visualization ● nx dep-graph ● nx affected:dep-graph 15

Slide 16

Slide 16 text

Effective change detection ● nx affected:lint ● nx affected:test ● nx affected:build ● nx affected:e2e 16

Slide 17

Slide 17 text

Distributed caching for faster CI 17 https://blog.nrwl.io/distributed-caching-in-nx-164edfbc68e0

Slide 18

Slide 18 text

Nx ecosystem ● Nx Console ○ VS Code extension ● Nx Plugin ○ Custom builder ● Nx Cloud ○ Cloud distributed caching 18 https://nx.dev/nx-console

Slide 19

Slide 19 text

Nx v10 ● https://github.com/nrwl/nx/issues/2152 ○ Stability ○ Smarter affected ○ Distributed caching by default ○ Mixing monorepo and polyrepo 19

Slide 20

Slide 20 text

Recap ● Nx makes managing monorepos easy! ○ Supports ○ https://nx.dev/ ● Try it now! 20 $ npx create-nx-workspace

Slide 21

Slide 21 text

Thank you! @puku0x Noriyuki Shinpuku