|
1 |
| -# micro-app-react |
| 1 | +# Topcoder React Microapp Example |
| 2 | + |
| 3 | +This is a [single-spa](https://single-spa.js.org/) example React 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 | + |
| 12 | +## NPM Commands |
| 13 | + |
| 14 | +| Command | Description | |
| 15 | +| --------------------- | ----------------------------------------------------------------- | |
| 16 | +| `npm start` | Run server which serves production ready build from `dist` folder | |
| 17 | +| `npm run dev` | Run app in the development mode | |
| 18 | +| `npm run dev-https` | Run app in the development mode using HTTPS protocol | |
| 19 | +| `npm run build` | Build app for production and puts files to the `dist` folder | |
| 20 | +| `npm run analyze` | Analyze dependencies sizes and opens report in the browser | |
| 21 | +| `npm run lint` | Check code for lint errors | |
| 22 | +| `npm run format` | Format code using prettier | |
| 23 | +| `npm run test` | Run unit tests | |
| 24 | +| `npm run watch-tests` | Watch for file changes and run unit tests on changes | |
| 25 | +| `npm run coverage` | Generate test code coverage report | |
| 26 | + |
| 27 | +## Local Deployment |
| 28 | + |
| 29 | +Inside the project folder run: |
| 30 | + |
| 31 | +- `npm i` - install dependencies |
| 32 | +- `npm run dev` - run app in development mode |
| 33 | +- 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:8500/topcoder-micro-frontends-react-app.js`. |
| 34 | + |
| 35 | +## Deployment to Production |
| 36 | + |
| 37 | +- `npm i` - install dependencies |
| 38 | +- `npm build` - build code to `dist/` folder |
| 39 | +- Now you can host `dist/` folder using any static server. For example, you may run a simple `Express` server by running `npm start`. |
| 40 | + |
| 41 | +### Deploying to Heroku |
| 42 | + |
| 43 | +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: |
| 44 | + |
| 45 | +- If there is not Git repository inited yet, create a repo and commit all the files: |
| 46 | + - `git init` |
| 47 | + - `git add .` |
| 48 | + - `git commit -m'inital commit'` |
| 49 | +- `heroku apps:create` - create Heroku app |
| 50 | +- `git push heroku master` - push changes to Heroku and trigger deploying |
| 51 | +- Now you have to configure frame app to use the URL provided by Heroku like `https://<APP-NAME>.herokuapp.com/topcoder-micro-frontends-react-app.js` to load this microapp. |
0 commit comments