Skip to content

Commit a8b7cbd

Browse files
committed
Improve to the development setup documentation
Copy the initial section on setting up a development environment from the Core repository developer documentation. Explicitly separate the instructions for doing a manual setup from a devcontainer setup. Move the preferred devcontainer instructions to the top . Added some clarifications and cleanup to the other sections.
1 parent 774583f commit a8b7cbd

File tree

1 file changed

+73
-41
lines changed

1 file changed

+73
-41
lines changed

docs/frontend/development.md

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,111 @@ title: "Frontend development"
33
sidebar_label: "Development"
44
---
55

6+
```mdx-code-block
7+
import {useState} from 'react';
8+
9+
export const RepositoryOpener = () => {
10+
const [value, setValue] = useState(0);
11+
const repoUrl = `vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=${encodeURIComponent(value)}`;
12+
return <div>
13+
<input onInput={(ev) => setValue(ev.target.value)} style={{width: "80%", display: "inline-block", marginRight: 16}} />
14+
<a href={repoUrl}><button style={{cursor: value == "" ? "default" : "pointer"}} disabled={value == ""}>Open</button></a>
15+
</div>
16+
}
17+
```
18+
619
The Home Assistant frontend is built using web components. For more background about our technology choices, [see this blog post](https://developers.home-assistant.io/blog/2019/05/22/internet-of-things-and-the-modern-web.html).
720

821
:::caution
922
Do not use development mode in production. Home Assistant uses aggressive caching to improve the mobile experience. This is disabled during development so that you do not have to restart the server in between changes.
1023
:::
1124

12-
## Setting up the environment
25+
## Setup with Visual Studio Code + devcontainer
1326

14-
### Getting the code
27+
The easiest way to get started with development is to use Visual Studio Code with devcontainers. This approach will create a preconfigured development environment with all the tools you need. This approach is enabled for all Home Assistant repositories. [Learn more about devcontainers.](https://code.visualstudio.com/docs/remote/containers)
1528

16-
The first step is to fork the [frontend repository][hass-frontend] and add the upstream remote. You can place the forked repository anywhere on your system.
29+
**Prerequisites**
1730

18-
```shell
19-
git clone [email protected]:YOUR_GIT_USERNAME/frontend.git
20-
cd frontend
21-
git remote add upstream https://github.com/home-assistant/frontend.git
22-
```
31+
- [Docker](https://docs.docker.com/get-docker/)
32+
- [Visual Studio code](https://code.visualstudio.com/)
33+
- [Git](https://git-scm.com/)
2334

24-
### Configuring Home Assistant
35+
**Getting started:**
2536

26-
You will need to have an instance of Home Assistant set up. See our guide on [setting up a development environment](/development_environment.mdx).
37+
1. Go to [Home Assistant frontend repository][hass-frontend] and click "fork".
38+
2. Once your fork is created, copy the URL of your fork and paste it below, then click "Open":
39+
<RepositoryOpener />
40+
3. Your browser will prompt you if you want to use Visual Studio Code to open the link, click "Open Link".
41+
4. When Visual Studio Code asks if you want to install the Remote extension, click "Install".
42+
5. The Dev Container image will then be built (this may take a few minutes), after this your development environment will be ready.
2743

28-
Next step is to configure Home Assistant to use the development mode for the frontend. Do this by updating the frontend config in your `configuration.yaml` and set the path to the frontend repository that you cloned in the last step:
44+
In the future, if you want to get back to your development environment: open Visual Studio Code, click on the "Remote Explorer" button in the sidebar, select "Containers" at the top of the sidebar.
2945

30-
```yaml
31-
frontend:
32-
# Example absolute path: /home/paulus/dev/hass/frontend
33-
development_repo: /path/to/hass/frontend/
34-
```
46+
**Configuring Home Assistant**
3547

36-
If you are using Visual Studio Code with devcontainers for Home Assistant, you need to mount the `frontend` directory into the container. Add the following section to `.devcontainer/devcontainer.json`:
48+
1. Follow the [instructions for setting up a Home Assistant devcontainer](https://developers.home-assistant.io/docs/development_environment#developing-with-visual-studio-code--devcontainer)
49+
2. Mount the `frontend` directory into the Core devcontainer by adding the following section to `.devcontainer/devcontainer.json` file in the `core` repository.
3750

38-
```json
39-
"mounts": [
40-
"source=/path/to/hass/frontend,target=/workspaces/frontend,type=bind,consistency=cached"
41-
]
42-
```
51+
```json
52+
"mounts": [
53+
"source=/path/to/hass/frontend,target=/workspaces/frontend,type=bind,consistency=cached"
54+
]
55+
```
56+
57+
*Make sure that you exclude the change to `.devcontainer/devcontainer.json` from any PRs as it points to local `frontend` repository path.*
58+
3. Rebuild the Core devcontainer by running the `Dev Containers: Rebuild Container` command in Visual Studio Code to pickup the new `mounts` configuration if you used it before making the change.
59+
4. Update the Home Assistant configuration to point to the mounted `frontend` path.
4360

44-
The Home Assistant's devcontainer needs to get rebuilt via the `docker-build` [task](/development_environment.mdx#tasks), and the `configuration.yaml` should point to the path inside the container:
61+
```yaml
62+
frontend:
63+
development_repo: /workspaces/frontend/
64+
```
4565
46-
```yaml
47-
frontend:
48-
development_repo: /workspaces/frontend/
49-
```
66+
## Setup Manually
5067
51-
The change to `.devcontainer/devcontainer.json` should be excluded from any PR as it contains your local path to the `frontend` repository.
68+
**Getting Started:**
5269
53-
### Installing Node.js
70+
1. Fork and clone the [Home Assistant frontend repository][hass-frontend].
71+
2. Install Node.js
72+
73+
The preferred method is using [nvm](https://github.com/creationix/nvm). Follow the [nvm installation instructions](https://github.com/creationix/nvm#install-script) and then use it to install Node.js by runnig
5474
55-
Node.js is required to build the frontend. The preferred method of installing node.js is with [nvm](https://github.com/creationix/nvm). Install nvm using the instructions in the [README](https://github.com/creationix/nvm#install-script), and install the correct node.js by running the following command:
75+
```shell
76+
nvm install
77+
nvm use
78+
```
79+
80+
This installs the version of Node.js defined in the `.nvmrc` file and then sets it as the current active version.
81+
82+
If you're running on Windows, you will need to use an alternative version of nvm like [nvm-windows](https://github.com/coreybutler/nvm-windows). This version of nvm doesn't automatically pickup `.nvmrc` so you'll need to manually select the correct version.
83+
3. Install [Yarn](https://yarnpkg.com/en/), the package manager used by the frontend, using the [installation instructions](https://yarnpkg.com/en/docs/install)
84+
4. Install all of the development dependencies by running:
5685

57-
```shell
58-
nvm install
59-
```
86+
```shell
87+
script/bootstrap
88+
```
6089

61-
[Yarn](https://yarnpkg.com/en/) is used as the package manager for node modules. [Install yarn using the instructions here.](https://yarnpkg.com/en/docs/install)
90+
**Configuring Home Assistant:**
6291

63-
Next, development dependencies need to be installed to bootstrap the frontend development environment. First activate the right Node version and then download all the dependencies:
92+
*These instructions assume that you are also [manually running Home Assistant](https://developers.home-assistant.io/docs/development_environment#manual-environment)*
6493

65-
```shell
66-
nvm use
67-
script/bootstrap
94+
Update the `frontend` configuration section in your `configuration.yaml` to point to the path of the `frontend` repository you cloned
95+
96+
```yaml
97+
frontend:
98+
# Example absolute path: /home/paulus/dev/hass/frontend
99+
development_repo: /path/to/hass/frontend/
68100
```
69101
70102
## Development
71103
72-
During development, you will need to run the development script to maintain a development build of the frontend that auto updates when you change any of the source files. To run this server, run:
104+
Whenever you make changes to files during development, you need to rebuild the development environment so that the Home Assistant instance will pickup the changes. The `script/develop` script will monitor and auto-update the build whenever anything changes.
73105

74106
```shell
75-
nvm use
76107
script/develop
77108
```
78109

79-
Make sure you have cache disabled and correct settings to avoid stale content:
110+
Many files will be cached by your web browser so you should disable caching to avoid stale content:
80111

81112
:::info
82113
Instructions are for Google Chrome
@@ -122,3 +153,4 @@ hass --skip-pip-packages home-assistant-frontend
122153
```
123154

124155
[hass-frontend]: https://github.com/home-assistant/frontend
156+
[hass-core]: https://github.com/home-assistant/core

0 commit comments

Comments
 (0)