My goal is to have one Angular project with shared parts: functionality, classes, look, services and page components (header, footer, some directives). Then inside it has 2 (or more applications) that will use the shared parts and add on the top of it own components (pages) and routes.
Then these 2 application should build to different dist folders, so the can be deployed to different places (URLs). And I want to be able to run (serve) them at the same time (maybe on different ports).
I guess I should start with creating new applications inside project:
ng generate application app1 --routing
ng generate application app1 --routing
and library? (for shared components). Is that right?
How should I configure angular.json file for serve and build? And how should I configure app.module.ts files?
Direct from the Angular Guide Workspace and project file structure - Multiple projects
It continues on in a table to describe library project files and their purpose. I'd suggest reading up further on the documentation above and associated links as it is well documented and might get you up and running quickly.
To run multiple Angular apps on different ports just open another terminal and run
ng serve --port 1234
for each app. See Angular(2) - Running two projects with CLI