This project was generated with Angular CLI. It is an extended version of a new app generated with ng new. It adds Library support for multiple apps in a mono-repo.
This starter is a result of many workarounds in order to make angular-cli work with a shared library of components/services/modules etc.
Currently supports:
- Library can be published and imported from npm registry (supports lazy loading and aot, Example2)
- Serving multiple apps at the same time
- Production build of multiple apps (with AOT)
- Shared Library of components/modules ( can be shared between each app with
@shared/) - Shared assets folder and polyfills. ( can be shared between each app )
- Shared SCSS. ( can be shared between each app )
- lazy loading of Shared modules
- Shared modules can lazy load other Shared modules ( with/without routes )
- Unit tests for each app
- E2E tests for each app
- Custom commands to make your life easier
- Universal Integration for multiple apps (need to install webpack for local serve
npm install -g webpack)
and everything else you would normally be able to do with an app generated with ng new.
Feel free to ask questions, provide feedback, submit ideas, requests or create an issue.
Star and support this project if you like it, to help it stay alive and maybe even be added as a boilerplate/starter to angular-cli (e.x. ng new app-name --template library).
Versioning of this project will follow the same with Angular-cli. There will be a separate branch that will be working for each version (starting with 1.2.7)
Just git clone this repo and start using it (run npm install after). The result would be the same if you had created a new app with Angular-CLI (ng new) having made all the necessary changes so that you can use multiple apps with a shared Library of components and have extra functionality.
The repo also includes examples of some use cases to help you out:
- AngularCLI:
AngularCLImodule is lazy loaded from the shared Libary (@shared) as a component/module of the default view/route. - Example1: In example 1
Example1module is lazy loaded from the shared Libary (@shared) as a view/route. - Example2: In example 2, the lazy loaded shared module
Example1lazy loads another shared moduleExample2. AlsoAngularCLImodule is lazily loaded and imported from the angular-cli-library (npm registry)
- Run
npm run app1to serve app1 (runsng serve --app app1 --port 4200) - Run
npm run app2to serve app2 etc. (runsng serve --app app2 --port 4201)
Names can change if you want (package.json). You can have multiple apps running in your browser as each app is launched on a different port. Navigate to http://localhost:4200/ or http://localhost:4201/ for example. Each app will automatically reload if you change any of the source files (if you edit your shared library both apps will reload if they are using it).
- Run
npm run library:publishto publish your library to npm registry. It is the same as runningnpm publishinsrc/sharedfolder.
- Run
npm run app1:buildto build app1. (runsng build --app app1 --prod --build-optimizer) - Run
npm run app2:buildto build app2 etc. (runsng build --app app2 --prod --build-optimizer)
The build artifacts will be stored in the dist/app1 or dist/app2 directory. All builds are for production ( --prod ).
Run ng generate component component-name to generate a new component. To add a component to app1 specify app.module as in the following example: ng g component default --module ../app.module.ts. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.
- Run
npm run app1:testto run *.spec.ts tests in app1 folder. (runsng test --app app1) - Run
npm run app2:testto run *.spec.ts tests in app2 folder. (runsng test --app app2)
- Run
npm run app1:e2eto run e2e tests from e2e/app1 folder. (runsng e2e --app app1) - Run
npm run app2:e2eto run e2e tests from e2e/app2 folder. (runsng e2e --app app2)
To get more help on the Angular CLI use ng help or go check out the Angular CLI README.