asynqmon/ui/README.md

54 lines
2.9 KiB
Markdown
Raw Normal View History

2021-01-31 11:10:10 +08:00
# Working with the React UI
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
This file explains how to work with Asynqmon UI.
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
## Introduction
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
The Asynqmon UI was bootstrapped using [Create React App](https://github.com/facebook/create-react-app), a popular toolkit for generating React application setups. You can find general information about Create React App on [their documentation site](https://create-react-app.dev/).
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
Instead of plain JavaScript, we use [TypeScript](https://www.typescriptlang.org/) to ensure typed code.
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
## Development environment
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
To work with the React UI code, you will need to have the following tools installed:
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
- The [Node.js](https://nodejs.org/) JavaScript runtime.
- The [Yarn](https://yarnpkg.com/) package manager.
- _Recommended:_ An editor with TypeScript, React, and [ESLint](https://eslint.org/) linting support. See e.g. [Create React App's editor setup instructions](https://create-react-app.dev/docs/setting-up-your-editor/). If you are not sure which editor to use, we recommend using [Visual Studio Code](https://code.visualstudio.com/docs/languages/typescript). Make sure that [the editor uses the project's TypeScript version rather than its own](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript).
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
**NOTE**: When using Visual Studio Code, be sure to open the `ui/` directory in the editor instead of the root of the repository. This way, the right ESLint and TypeScript configuration will be picked up from the React workspace.
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
## Installing npm dependencies
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
The React UI depends on a large number of [npm](https://www.npmjs.com/) packages. These are not checked in, so you will need to download and install them locally via the Yarn package manager:
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
yarn
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
Yarn consults the `package.json` and `yarn.lock` files for dependencies to install. It creates a `node_modules` directory with all installed dependencies.
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
**NOTE**: Remember to change directory to `ui/` before running this command and the following commands.
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
## Running a local development server
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
You can start a development server for the React UI outside of a running Asynqmon server by running:
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
yarn start
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
This will open a browser window with the React app running on http://localhost:3000/. The page will reload if you make edits to the source code. You will also see any lint errors in the console.
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
## Building the app for production
2020-11-24 22:54:00 +08:00
2021-01-31 11:10:10 +08:00
To build a production-optimized version of the React app to a `build` subdirectory, run:
yarn build
**NOTE:** You will likely not need to do this directly. Instead, this is taken care of by the `build` target in the main Asynqmon `Makefile` when building the full binary.
## Integration into Asynqmon
To build a Asynqmon binary that includes a compiled-in version of the production build of the React app, change to the root of the repository and run:
make build
This installs npm dependencies via Yarn, builds a production build of the React app, and then finally compiles in all web assets into the Asynqmon binary.