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

Commit 8219501

Browse files
committed
Config file changes
1 parent 6e4f6dd commit 8219501

10 files changed

+52
-37
lines changed

README.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ This `micro-frontends-frame` app configs 2 things:
2222

2323
1. URLs to all microapps it can load inside
2424

25-
- edit `src/public/importmap-production.json` to configure microapp names and URL to be used when deployed to production
26-
- edit `src/public/importmap-local.json` to configure microapp names and URL to be used when deployed to locally
25+
- edit `config/production.json` to configure microapp names and URL to be used when deployed to production environment
26+
- edit `config/development.json` to configure microapp names and URL to be used when deployed to development environment
27+
- edit `config/local.json` to configure microapp names and URL to be used when deployed locally
2728

2829
2. Mapping between URL path and microapp to load by that path in `src/index.ejs`.
2930

@@ -37,28 +38,29 @@ This `micro-frontends-frame` app configs 2 things:
3738

3839
## NPM Commands
3940

40-
| Command | Description |
41-
| ---------------- | ----------------------------------------------------------------- |
42-
| `npm start` | Run server which serves production ready build from `dist` folder |
43-
| `npm run dev` | Run app in the development mode |
44-
| `npm run build` | Build app for production and puts files to the `dist` folder |
45-
| `npm run lint` | Check code for lint errors |
46-
| `npm run format` | Format code using prettier |
47-
| `npm run test` | Run unit tests |
41+
| Command | Description |
42+
| -------------------- | ----------------------------------------------------------------- |
43+
| `npm start` | Run server which serves production ready build from `dist` folder |
44+
| `npm run local` | Run app in the development mode on local machine |
45+
| `npm run build-dev` | Build app for development and puts files to the `dist` folder |
46+
| `npm run build-prod` | Build app for production and puts files to the `dist` folder |
47+
| `npm run lint` | Check code for lint errors |
48+
| `npm run format` | Format code using prettier |
49+
| `npm run test` | Run unit tests |
4850

4951
## Local Deployment
5052

5153
To deploy `micro-frontends-frame` app locally run inside the project root:
5254

5355
- `npm i` to install dependencies
54-
- `npm run dev` to start the app on port `3000`
56+
- `npm run local` to start the app on port `3000`
5557

5658
Note, that to make authorization work locally, you have to use domain `local.topcoder-dev.com` with port `3000`. So you should add into your `/etc/hosts` the line `127.0.0.1 local.topcoder-dev.com` and open app by URL http://local.topcoder-dev.com:3000.
5759

5860
## Deployment to Production
5961

6062
- `npm i` - install dependencies
61-
- `npm run build` - build code to `dist/` folder
63+
- `npm run build-prod` - build code to `dist/` folder
6264
- Now you can host `dist/` folder using any static server with fallback to `index.html` file for any not found route. For example, you may run a simple `Express` server by running `npm start`.
6365

6466
### Deploying to Heroku
@@ -77,7 +79,7 @@ Make sure you have [Heroky CLI](https://devcenter.heroku.com/articles/heroku-cli
7779

7880
For adding a child app to the root app make the following steps:
7981

80-
1. Add child app path to importmap. User file `micro-frontends-frame/src/public/importmap-local.json` for local deployment and `micro-frontends-frame/src/public/importmap-production.json` for production:
82+
1. Add child app path to importmap. File underpath `micro-frontends-frame/config/local.json` for local deployment, `micro-frontends-frame/config/development.json` for development deployment and `micro-frontends-frame/config/production.json` for production deployment:
8183

8284
React example:
8385

config/development.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"imports": {
3+
"@topcoder/micro-frontends-navbar-app": "https://www.topcoder-dev.com/topcoder-micro-frontends-navbar-app.js",
4+
"@topcoder/micro-frontends-react-app": "https://www.topcoder-dev.com/topcoder-micro-frontends-react-app.js",
5+
"@topcoder/micro-frontends-angular-app": "https://www.topcoder-dev.com/main.js"
6+
}
7+
}
8+
s

config/local.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"imports": {
3+
"@topcoder/micro-frontends-navbar-app": "http://localhost:8080/topcoder-micro-frontends-navbar-app.js",
4+
"@topcoder/micro-frontends-react-app": "http://localhost:8500/topcoder-micro-frontends-react-app.js",
5+
"@topcoder/micro-frontends-angular-app": "http://localhost:4200/main.js"
6+
}
7+
}

config/production.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"imports": {
3+
"@topcoder/micro-frontends-navbar-app": "https://www.topcoder.com/topcoder-micro-frontends-navbar-app.js",
4+
"@topcoder/micro-frontends-react-app": "https://www.topcoder.com/topcoder-micro-frontends-react-app.js",
5+
"@topcoder/micro-frontends-angular-app": "https://www.topcoder.com/main.js"
6+
}
7+
}

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"name": "@topcoder/micro-frontends-frame",
33
"scripts": {
44
"start": "node server.js",
5-
"dev": "webpack-dev-server --mode=development --port 3000 --env.isLocal=true",
5+
"local": "webpack-dev-server --mode=development --port 3000 --env.config=local",
66
"lint": "eslint src --ext js",
77
"test": "cross-env BABEL_ENV=test jest --passWithNoTests",
88
"format": "prettier --write \"./**\"",
9-
"build": "webpack --mode=production"
9+
"build-dev": "webpack --mode=development --env.config=dev",
10+
"build-prod": "webpack --mode=production --env.config=prod"
1011
},
1112
"devDependencies": {
1213
"@babel/core": "^7.7.4",

src/index.ejs

+7-6
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
</script>
4747
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/lib/system/single-spa.min.js" as="script">
4848

49-
<!-- Add your organization's prod import map URL to this script's src -->
50-
<script type="systemjs-importmap" src="/importmap-production.json"></script>
51-
52-
<% if (htmlWebpackPlugin.options.isLocal) { %>
53-
<script type="systemjs-importmap" src="/importmap-local.json"></script>
49+
<% if (htmlWebpackPlugin.options.templateParameters.env == "local") { %>
50+
<script type="systemjs-importmap" src="/local.json"></script>
51+
<% } else if (htmlWebpackPlugin.options.templateParameters.env == "dev") { %>
52+
<script type="systemjs-importmap" src="/development.json"></script>
53+
<% } else if (htmlWebpackPlugin.options.templateParameters.env == "prod") { %>
54+
<script type="systemjs-importmap" src="/production.json"></script>
5455
<% } %>
5556

5657
<!--
@@ -59,7 +60,7 @@
5960
-->
6061
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/zone.min.js"></script>
6162

62-
<% if (htmlWebpackPlugin.options.isLocal) { %>
63+
<% if (htmlWebpackPlugin.options.templateParameters.isLocal) { %>
6364
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/import-map-overrides.js"></script>
6465
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/system.js"></script>
6566
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/extras/amd.js"></script>

src/public/importmap-local.json

-7
This file was deleted.

src/public/importmap-production.json

-7
This file was deleted.
File renamed without changes.

webpack.config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ module.exports = (webpackConfigEnv) => {
2121
inject: false,
2222
template: "src/index.ejs",
2323
templateParameters: {
24-
isLocal: webpackConfigEnv && webpackConfigEnv.isLocal === "true",
24+
env: webpackConfigEnv.config,
2525
orgName,
2626
},
2727
}),
2828
new CopyWebpackPlugin({
29-
patterns: [{ from: "src/public", to: "./" }],
29+
patterns: [
30+
{ from: "src/reuse", to: "./" },
31+
{ from: 'config/', to: './' }
32+
],
3033
}),
3134
],
3235
});

0 commit comments

Comments
 (0)