A reference example monorepo with Nx + Storybook + Atomic Design in Angular
Made by Codestar powered by Ordina
For more info see the Intro
- Run storybook:
yarn docs:json && yarn nx storybook
(does nx run demo:storybook) ornx run ui:storybook
. So modify apps/demo/.storybook/main.js to also include libs/ui and then useyarn nx storybook
- Also run
yarn nx serve server
in a separate terminal - To build storybook run:
yarn nx run demo:build-storybook
- Run lint on all projects:
yarn nx run-many --all --target=lint
(withyarn nx lint
only the default project is linted)
yarn import rm package-lock.json yarn add --dev @nrwl/storybook yarn nx g @nrwl/angular:storybook-configuration demo yarn nx g @nrwl/angular:lib ui yarn nx g @nrwl/angular:storybook-configuration ui yarn nx g @nrwl/angular:component button --project=ui --export yarn nx g @nrwl/angular:stories --name=ui yarn nx g @nrwl/angular:component LoadingButton --project=ui --export yarn nx g @nrwl/angular:stories --name=ui
yarn add -D @nrwl/express yarn add cors yarn add -D @types/cors yarn nx g @nrwl/express:application server yarn nx g @nrwl/node:library btc yarn nx g service BtcRate Note that modules (e.g. HttpClientModule or UiModule) need to be added to both app.module.ts and app.component.stories.ts
yarn nx g @nrwl/workspace:lib shared/types yarn nx g @nrwl/angular:lib shared/services yarn nx g @nrwl/angular:service Message --project=shared-services --export manually export from services/lib/index.ts yarn nx g @nrwl/angular:lib shared/data-access yarn nx g @nrwl/angular:service btcRate/BtcRate --project=shared-data-access --export manually export from data-access/lib/index.ts yarn nx g @nrwl/angular:service MinimalLogger --project=shared-types --export yarn nx g @nrwl/angular:component Alert --project=ui --export
https://github.com/storybookjs/storybook/blob/master/addons/docs/angular/README.md
yarn add -D @compodoc/compodoc
Add to package.json: "docs:json": "compodoc -p ./tsconfig.base.json -e json -d ."
yarn docs:json // TODO this now needs to be run manually after each type change, then also storybook needs to be restarted
No stories generated because there were no components declared in /libs/ui/src/lib/ui.module.ts. Hint: you can always generate stories later with the 'nx generate @nrwl/angular:stories --name=ui' command
Target:
- React: 1 field, current balance
- Ng: more complex: portfolio, transactions, graph of balance over time (and use UI lib components in this MicroApp)
From https://nx.dev/l/a/guides/setup-mfe-with-angular
- This document explains that webpack 5 is required. After upgrading to the newest version of nx, and running
yarn why webpack
gives both webpack 4 and some special packages that end in webpack5. Let's try the recommended steps. - yarn nx g @nrwl/angular:app dashboard --mfe --mfeType=host --routing=true
- yarn nx g @nrwl/angular:app login --mfe --mfeType=remote --port=4201 --host=dashboard --routing=true
- seems to work, stash results
- yarn nx g mv --project demo demoOld
- yarn nx g mv --project demo-e2e demo-e2eOld
- yarn nx g @nrwl/angular:app demo --mfe --mfeType=host --routing=true
- yarn nx run demo:serve-mfe
- Update the content of apps/demo/src/app/* with apps/demoOld/src/app/*, same with .storybook files
- yarn nx g rm demoOld and reset the default project in in nx.json to demo
- yarn nx g @nrwl/angular:app portfolio --mfe --mfeType=remote --port=4201 --host=demo --routing=true
- test only portfolio, by running
yarn nx run portfolio:serve
- test only shell app:
yarn nx run demo:serve:development
- test integration, run
yarn nx run demo:serve-mfe
which will start both servers, view on http://localhost:4200/nx-reference-shell
This project was generated using Nx.
10-minute video showing all Nx features
Nx supports many plugins which add capabilities for developing different types of applications and different tools.
These capabilities include generating applications, libraries, etc as well as the devtools to test, and build projects as well.
Below are our core plugins:
- Angular
ng add @nrwl/angular
- React
ng add @nrwl/react
- Web (no framework frontends)
ng add @nrwl/web
- Nest
ng add @nrwl/nest
- Express
ng add @nrwl/express
- Node
ng add @nrwl/node
There are also many community plugins you could add.
Run ng g @nrwl/angular:app my-app
to generate an application.
You can use any of the plugins above to generate applications as well.
When using Nx, you can create multiple applications and libraries in the same workspace.
Run ng g @nrwl/angular:lib my-lib
to generate a library.
You can also use any of the plugins above to generate libraries as well.
Libraries are shareable across libraries and applications. They can be imported from @star/mylib
.
Run ng serve my-app
for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.
Run ng g component my-component --project=my-app
to generate a new component.
Run ng build my-app
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Run ng test my-app
to execute the unit tests via Jest.
Run nx affected:test
to execute the unit tests affected by a change.
Run ng e2e my-app
to execute the end-to-end tests via Cypress.
Run nx affected:e2e
to execute the end-to-end tests affected by a change.
Run nx dep-graph
to see a diagram of the dependencies of your projects.
Visit the Nx Documentation to learn more.
Nx Cloud pairs with Nx in order to enable you to build and test code more rapidly, by up to 10 times. Even teams that are new to Nx can connect to Nx Cloud and start saving time instantly.
Teams using Nx gain the advantage of building full-stack applications with their preferred framework alongside Nx’s advanced code generation and project dependency graph, plus a unified experience for both frontend and backend developers.
Visit Nx Cloud to learn more.