- Monorepo
- Micro frontends
- Ui library
https://nrwl.io/ Optimize and modernize your development practices
Angular CLI: 13.3.5
Node: 14.19.2
Package Manager: npm 6.14.17
OS: darwin x64
@angular-devkit/architect 0.1303.5 (cli-only)
@angular-devkit/core 13.3.5 (cli-only)
@angular-devkit/schematics 13.3.5 (cli-only)
@schematics/angular 13.3.5 (cli-only)
npx create-nx-workspace blink-mfe --preset=empty
npm install --save-dev @nrwl/angular
nx g @nrwl/angular:host host --remotes=sign-in,sign-up
nx serve host --devRemotes=sign-in,sign-up
nx build sign-in
nx build sign-up
To simulate a production deployment and host the applications independently, we must install a library that can serve the applications.
npm install -g http-server
http-server -p 8081 --cors -c-1 ./dist/apps/sign-in
http-server -p 8082 --cors -c-1 ./dist/apps/sign-up
Note:
pay attention to each http port,
these are needed to configure the host application inmodule-federation.config.js file
const { withModuleFederation } = require('@nrwl/angular/module-federation');
const config = require('./module-federation.config');
module.exports = withModuleFederation({
...config,
remotes: [
['sign-in', 'http://127.0.0.1:8081'],
['sign-up', 'http://127.0.0.1:8082'],
]
});
http-server -p 8080 --cors -c-1 ./dist/apps/host
http-server -p 8081 --cors -c-1 ./dist/apps/sign-in
http-server -p 8082 --cors -c-1 ./dist/apps/sign-up
======================================================
npx nx generate @nrwl/workspace:library shared-module --no-interactive
...
+-- apps
| > host
| > sign-in
| > sign-up
...
+-- libs
| > shared-model
and now we will try a command offered by nw to know which application has the shared-model library as a dependency
nx affected:graph
note
When the browser with the graphics opens, click the show affected projects button to see the library's dependency on other projects
npx nx g @nrwl/angular:library ui-toolkit --no-interactive
npx nx g @nrwl/angular:component button --project=ui-toolkit --no-interactive --export
nx affected:graph
1. npx create-nx-workspace blink-mfe --preset=empty
2. npm install --save-dev @nrwl/angular
3. nx g @nrwl/angular:host host --remotes=sign-in,sign-up
4. nx serve host --devRemotes=sign-in,sign-up
5. npx nx generate @nrwl/workspace:library shared-module --no-interactive
6. npx nx g @nrwl/angular:library ui-toolkit --no-interactive
7. npx nx g @nrwl/angular:component button --project=ui-toolkit --no-interactive --export
8. nx affected:graph