Skip to content

Commit d128e91

Browse files
committed
Update react on wsl guide
1 parent be973a5 commit d128e91

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

hub/dev-environment/javascript/react-on-wsl.md

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,65 +11,52 @@ ms.date: 03/30/2021
1111

1212
# Install React on Windows Subsystem for Linux
1313

14-
This guide will walk through installing React on a Linux distribution (ie. Ubuntu) running on the Windows Subsystem for Linux (WSL) using the [create-react-app](https://github.com/facebook/create-react-app) toolchain.
14+
This guide will walk through installing React on a Linux distribution (ie. Ubuntu) running on the Windows Subsystem for Linux (WSL) using the [vite](https://vitejs.dev/) frontend tooling.
1515

16-
We recommend following these instructions if you are creating a single-page app (SPA) that you would like to use Bash commands or tools with and/or plan to deploy to a Linux server or use Docker containers. If you are brand new to React and just interested in learning, you may want to consider [installing with create-react-app directly on Windows](./react-on-windows.md).
16+
We recommend following these instructions if you are creating a single-page app (SPA) that you would like to use Bash commands or tools with and/or plan to deploy to a Linux server or use Docker containers. If you are brand new to React and just interested in learning, you may want to consider [installing with vite directly on Windows](./react-on-windows.md).
1717

1818
For more general information about React, deciding between React (web apps), React Native (mobile apps), and React Native for Windows (desktop apps), see the [React overview](./react-overview.md).
1919

2020
## Prerequisites
2121

2222
- Install the latest version of Windows 10 (Version 1903+, Build 18362+) or Windows 11
2323
- [Install Windows Subsystem for Linux (WSL)](/windows/wsl/install-win10), including a Linux distribution (like Ubuntu) and make sure it is running in WSL 2 mode. You can check this by opening PowerShell and entering: `wsl -l -v`
24-
- [Install Node.js on WSL 2](./nodejs-on-wsl.md): These instructions use Node Version Manager (nvm) for installation, you will need a recent version of NodeJS to run create-react-app, as well as a recent version of Node Package Manager (npm). For exact version requirements, see the [Create React App website](https://reactjs.org/docs/create-a-new-react-app.html#create-react-app).
24+
- [Install Node.js on WSL 2](./nodejs-on-wsl.md): These instructions use Node Version Manager (nvm) for installation, you will need a recent version of NodeJS to run vite, as well as a recent version of Node Package Manager (npm).
2525

2626
> [!IMPORTANT]
2727
> Installing a Linux distribution with WSL will create a directory for storing files: `\\wsl\Ubuntu-20.04` (substitute Ubuntu-20.04 with whatever Linux distribution you're using). To open this directory in Windows File Explorer, open your WSL command line, select your home directory using `cd ~`, then enter the command `explorer.exe .` Be careful not to install NodeJS or store files that you will be working with on the mounted C drive (`/mnt/c/Users/yourname$`). Doing so will significantly slow down your install and build times.
2828
2929
## Install React
3030

31-
To install the full React toolchain on WSL, we recommend using create-react-app:
31+
To install the full React toolchain on WSL, we recommend using vite.
3232

3333
1. Open a WSL command line (ie. Ubuntu).
3434

3535
2. Create a new project folder: `mkdir ReactProjects` and enter that directory: `cd ReactProjects`.
3636

37-
3. Install React using [npx](https://www.npmjs.com/package/npx):
37+
3. Install React using vite :
3838

3939
```bash
40-
npx create-react-app my-app
40+
npm create vite@latest my-react-app -- --template react
4141
```
4242

43-
>[!NOTE]
44-
> [npx](https://www.npmjs.com/package/npx) is the package runner used by npm to execute packages in place of a global install. It basically creates a temporary install of React so that with each new project you are using the most recent version of React (not whatever version was current when you performed the global install above). Using the NPX package runner to execute a package can also help reduce the pollution of installing lots of packages on your machine.
45-
46-
4. This will first ask for your permission to temporarily install create-react-app and it's associated packages. Once completed, change directories into your new app ("my-app" or whatever you've chosen to call it): `cd my-app`.
47-
48-
5. Start your new React app:
49-
50-
```Bash
51-
npm start
52-
```
43+
4. Once installed, change directories into your new app ("my-react-app" or whatever you've chosen to call it): `cd my-react-app`, install the dependencies: `npm install` and then start your local development server: `npm run dev`
5344
5445
This command will start up the Node.js server and launch a new browser window displaying your app. You can use **Ctrl + c** to stop running the React app in your command line.
5546
56-
> [!NOTE]
57-
> Create React App includes a frontend build pipeline using [Babel](https://babeljs.io/) and [webpack](https://webpack.js.org/), but doesn't handle backend logic or databases. If you are seeking to build a server-rendered website with React that uses a Node.js backend, we recommend [installing Next.js](./nextjs-on-wsl.md), rather than this create-react-app installation, which is intended more for single-page apps. You also may want to consider [installing Gatsby](./gatsby-on-wsl.md) if you want to build a static content-oriented website.
58-
59-
6. When you're ready to deploy your web app to production, running `npm run build` will create a build of your app in the "build" folder. You can learn more in the [Create React App User Guide](https://create-react-app.dev/docs/deployment).
60-
61-
## Add React to an existing web app
47+
> [!NOTE]
48+
> Vite includes a frontend build pipeline using [Babel](https://babeljs.io/), [esbuild](https://esbuild.github.io/) and [Rollup](https://rollupjs.org/), but doesn't handle backend logic or databases. If you are seeking to build a server-rendered website with React that uses a Node.js backend, we recommend [installing Next.js](./nextjs-on-wsl.md), rather than this Vite installation, which is intended more for single-page apps(SPAs). You also may want to consider [installing Gatsby](./gatsby-on-wsl.md) if you want to build a static content-oriented website.
6249

63-
Since React is a JavaScript library that is, in its most basic form, just a collection of text files, you can create React apps without installing any tools or libraries on your computer. You may only want to add a few "sprinkles of interactivity" to a web page and not need build tooling. You can add a React component by just adding a plain `<script>` tag on an HTML page. Follow the ["Add React in One Minute"](https://reactjs.org/docs/add-react-to-a-website.html) steps in the React docs.
50+
6. When you're ready to deploy your web app to production, running `npm run build` to create a build of your app in the "dist" folder. You can learn more in the [Deploying a Static Site](https://vitejs.dev/guide/static-deploy.html).
6451
6552
## Additional resources
6653
67-
- [React docs](https://reactjs.org/)
68-
- [Create React App docs](https://create-react-app.dev/docs/getting-started)
54+
- [React docs](https://react.dev)
55+
- [Vite](https://vitejs.dev/)
6956
- [Install Next.js](./nextjs-on-wsl.md)
7057
- [Install Gatsby](./gatsby-on-wsl.md)
7158
- [Install React Native for Windows](https://microsoft.github.io/react-native-windows/docs/getting-started)
7259
- [Install NodeJS on Windows](./nodejs-on-windows.md)
7360
- [Install NodeJS on WSL](./nodejs-on-wsl.md)
7461
- Try the tutorial: [Using React in Visual Studio Code](https://code.visualstudio.com/docs/nodejs/reactjs-tutorial)
75-
- Try the [React learning path](/training/paths/react/)
62+
- Try the [React learning path](/training/paths/react/)

0 commit comments

Comments
 (0)