Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 769cb61

Browse files
committed
Baseline for the Angular App
1 parent 8924f4f commit 769cb61

35 files changed

+14728
-1
lines changed

.browserslistrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2+
# For additional information regarding the format and rule options, please see:
3+
# https://github.com/browserslist/browserslist#queries
4+
5+
# For the full list of supported browsers by the Angular framework, please see:
6+
# https://angular.io/guide/browser-support
7+
8+
# You can see what browsers were selected by your queries by running:
9+
# npx browserslist
10+
11+
last 1 Chrome version
12+
last 1 Firefox version
13+
last 2 Edge major versions
14+
last 2 Safari major versions
15+
last 2 iOS major versions
16+
Firefox ESR
17+
not IE 9-10 # Angular support for IE 9-10 has been deprecated and will be removed as of Angular v11. To opt-in, remove the 'not' prefix on this line.
18+
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Editor configuration, see https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.ts]
12+
quote_type = single
13+
14+
[*.md]
15+
max_line_length = off
16+
trim_trailing_whitespace = false

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,48 @@
1-
# micro-app-angular
1+
# Topcoder Angular Microapp Example
2+
3+
This is a [single-spa](https://single-spa.js.org/) example Angular microapp.
4+
5+
> NOTE. This application have been configured to be run as child app of a single-spa application. So while this app can be deployed and run independently, we would need some frame [single-spa](https://single-spa.js.org/) which would load it. While technically we can achieve running this app as standalone app it's strongly not recommended by the author of the `single-spa` approch, see this [GitHub Issue](https://github.com/single-spa/single-spa/issues/640) for details.
6+
7+
## Requirements
8+
9+
- Node.js 8+
10+
- Npm 6+
11+
- Angular CLI 10
12+
13+
## NPM Commands
14+
15+
| Command | Description |
16+
| --------------------- | ----------------------------------------------------------------- |
17+
| `npm start` | Run server which serves production ready build from `dist` folder |
18+
| `npm run dev` | Run app in the development mode |
19+
| `npm run dev-https` | Run app in the development mode using HTTPS protocol |
20+
| `npm run build` | Build app for production and puts files to the `dist` folder |
21+
| `npm run lint` | Check code for lint errors |
22+
| `npm run test` | Run unit tests |
23+
24+
## Local Deployment
25+
26+
Inside the project folder run:
27+
28+
- `npm i` - install dependencies
29+
- `npm run dev` - run app in development mode
30+
- As this app can be loaded only inside a frame single-spa, you have to run a `root-config` frame app and configure it to use the URL `http://localhost:4200/main.js`.
31+
32+
## Deployment to Production
33+
34+
- `npm i` - install dependencies
35+
- `npm build` - build code to `dist/micro-frontends-angular-app` folder
36+
- Now you can host `dist/micro-frontends-angular-app` folder using any static server. For example, you may run a simple `Express` server by running `npm start`.
37+
38+
### Deploying to Heroku
39+
40+
Make sure you have [Heroky CLI](https://devcenter.heroku.com/articles/heroku-cli) installed and you have a Heroku account. And then inside the project folder run the next commands:
41+
42+
- If there is not Git repository inited yet, create a repo and commit all the files:
43+
- `git init`
44+
- `git add .`
45+
- `git commit -m'inital commit'`
46+
- `heroku apps:create` - create Heroku app
47+
- `git push heroku master` - push changes to Heroku and trigger deploying
48+
- Now you have to configure frame app to use the URL provided by Heroku like `https://<APP-NAME>.herokuapp.com/main.js` to load this microapp.

angular.json

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"micro-frontends-angular-app": {
7+
"projectType": "application",
8+
"schematics": {
9+
"@schematics/angular:component": {
10+
"style": "scss"
11+
}
12+
},
13+
"root": "",
14+
"sourceRoot": "src",
15+
"prefix": "tc-ex",
16+
"architect": {
17+
"build": {
18+
"builder": "@angular-builders/custom-webpack:browser",
19+
"options": {
20+
"outputPath": "dist/micro-frontends-angular-app",
21+
"index": "src/index.html",
22+
"main": "src/main.single-spa.ts",
23+
"polyfills": "src/polyfills.ts",
24+
"tsConfig": "tsconfig.app.json",
25+
"aot": true,
26+
"assets": [
27+
"src/favicon.ico",
28+
"src/assets"
29+
],
30+
"styles": [
31+
"src/styles.scss"
32+
],
33+
"scripts": [],
34+
"customWebpackConfig": {
35+
"path": "extra-webpack.config.js",
36+
"libraryName": "micro-frontends-angular-app",
37+
"libraryTarget": "umd"
38+
}
39+
},
40+
"configurations": {
41+
"production": {
42+
"fileReplacements": [
43+
{
44+
"replace": "src/environments/environment.ts",
45+
"with": "src/environments/environment.prod.ts"
46+
}
47+
],
48+
"optimization": true,
49+
"outputHashing": "none",
50+
"sourceMap": false,
51+
"extractCss": true,
52+
"namedChunks": false,
53+
"extractLicenses": true,
54+
"vendorChunk": false,
55+
"buildOptimizer": true,
56+
"budgets": [
57+
{
58+
"type": "initial",
59+
"maximumWarning": "2mb",
60+
"maximumError": "5mb"
61+
},
62+
{
63+
"type": "anyComponentStyle",
64+
"maximumWarning": "6kb",
65+
"maximumError": "10kb"
66+
}
67+
]
68+
}
69+
}
70+
},
71+
"serve": {
72+
"builder": "@angular-builders/custom-webpack:dev-server",
73+
"options": {
74+
"browserTarget": "micro-frontends-angular-app:build"
75+
},
76+
"configurations": {
77+
"production": {
78+
"browserTarget": "micro-frontends-angular-app:build:production"
79+
}
80+
}
81+
},
82+
"extract-i18n": {
83+
"builder": "@angular-devkit/build-angular:extract-i18n",
84+
"options": {
85+
"browserTarget": "micro-frontends-angular-app:build"
86+
}
87+
},
88+
"test": {
89+
"builder": "@angular-devkit/build-angular:karma",
90+
"options": {
91+
"main": "src/test.ts",
92+
"polyfills": "src/polyfills.ts",
93+
"tsConfig": "tsconfig.spec.json",
94+
"karmaConfig": "karma.conf.js",
95+
"assets": [
96+
"src/favicon.ico",
97+
"src/assets"
98+
],
99+
"styles": [
100+
"src/styles.scss"
101+
],
102+
"scripts": []
103+
}
104+
},
105+
"lint": {
106+
"builder": "@angular-devkit/build-angular:tslint",
107+
"options": {
108+
"tsConfig": [
109+
"tsconfig.app.json",
110+
"tsconfig.spec.json",
111+
"e2e/tsconfig.json"
112+
],
113+
"exclude": [
114+
"**/node_modules/**"
115+
]
116+
}
117+
},
118+
"e2e": {
119+
"builder": "@angular-devkit/build-angular:protractor",
120+
"options": {
121+
"protractorConfig": "e2e/protractor.conf.js",
122+
"devServerTarget": "micro-frontends-angular-app:serve"
123+
},
124+
"configurations": {
125+
"production": {
126+
"devServerTarget": "micro-frontends-angular-app:serve:production"
127+
}
128+
}
129+
}
130+
}
131+
}
132+
},
133+
"defaultProject": "micro-frontends-angular-app",
134+
"cli": {
135+
"analytics": "8e69b5f2-d6cd-480a-91e3-0d66fc04553a"
136+
}
137+
}

e2e/protractor.conf.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// @ts-check
2+
// Protractor configuration file, see link for more information
3+
// https://github.com/angular/protractor/blob/master/lib/config.ts
4+
5+
const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter');
6+
7+
/**
8+
* @type { import("protractor").Config }
9+
*/
10+
exports.config = {
11+
allScriptsTimeout: 11000,
12+
specs: [
13+
'./src/**/*.e2e-spec.ts'
14+
],
15+
capabilities: {
16+
browserName: 'chrome'
17+
},
18+
directConnect: true,
19+
baseUrl: 'http://localhost:4200/',
20+
framework: 'jasmine',
21+
jasmineNodeOpts: {
22+
showColors: true,
23+
defaultTimeoutInterval: 30000,
24+
print: function() {}
25+
},
26+
onPrepare() {
27+
require('ts-node').register({
28+
project: require('path').join(__dirname, './tsconfig.json')
29+
});
30+
jasmine.getEnv().addReporter(new SpecReporter({
31+
spec: {
32+
displayStacktrace: StacktraceOption.PRETTY
33+
}
34+
}));
35+
}
36+
};

e2e/src/app.e2e-spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { AppPage } from './app.po';
2+
import { browser, logging } from 'protractor';
3+
4+
describe('workspace-project App', () => {
5+
let page: AppPage;
6+
7+
beforeEach(() => {
8+
page = new AppPage();
9+
});
10+
11+
it('should display welcome message', () => {
12+
page.navigateTo();
13+
expect(page.getTitleText()).toEqual('Angular child app example');
14+
});
15+
16+
afterEach(async () => {
17+
// Assert that there are no errors emitted from the browser
18+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19+
expect(logs).not.toContain(jasmine.objectContaining({
20+
level: logging.Level.SEVERE,
21+
} as logging.Entry));
22+
});
23+
});

e2e/src/app.po.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { browser, by, element } from 'protractor';
2+
3+
export class AppPage {
4+
navigateTo(): Promise<unknown> {
5+
return browser.get(browser.baseUrl) as Promise<unknown>;
6+
}
7+
8+
getTitleText(): Promise<string> {
9+
return element(by.css('tc-ex-root .content span')).getText() as Promise<string>;
10+
}
11+
}

e2e/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
{
3+
"extends": "../tsconfig.json",
4+
"compilerOptions": {
5+
"outDir": "../out-tsc/e2e",
6+
"module": "commonjs",
7+
"target": "es2018",
8+
"types": [
9+
"jasmine",
10+
"jasminewd2",
11+
"node"
12+
]
13+
}
14+
}

extra-webpack.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const singleSpaAngularWebpack = require('single-spa-angular/lib/webpack').default;
2+
3+
module.exports = (config, options) => {
4+
const singleSpaWebpackConfig = singleSpaAngularWebpack(config, options);
5+
6+
// Feel free to modify this webpack config however you'd like to
7+
return singleSpaWebpackConfig;
8+
};

karma.conf.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage-istanbul-reporter'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
clearContext: false // leave Jasmine Spec Runner output visible in browser
17+
},
18+
coverageIstanbulReporter: {
19+
dir: require('path').join(__dirname, './coverage/micro-frontends-angular-app'),
20+
reports: ['html', 'lcovonly', 'text-summary'],
21+
fixWebpackSourcePaths: true
22+
},
23+
reporters: ['progress', 'kjhtml'],
24+
port: 9876,
25+
colors: true,
26+
logLevel: config.LOG_INFO,
27+
autoWatch: true,
28+
browsers: ['Chrome'],
29+
singleRun: false,
30+
restartOnFileChange: true
31+
});
32+
};

0 commit comments

Comments
 (0)