Create a React project with Nx

Ye Min Ko
Learn React
Published in
3 min readJul 24, 2023
React + Typescript with Nx

Summary

Creating a React app is pretty straight forward. But it becomes tricky when we want to integrate with other tools like typescript, SASS, testing tools, CI, build tools and so on. Nx is a build system that can help you to achieve your desired integration without worrying about different configurations.

Prerequisites

Good to know

This tutorial will use the Nx to build a standalone React project. Which will also include the integration with typescript, SASS and Vite.

Create Nx Workspace

Whatever you want to create an application, the first thing to do is create a Nx workspace. Run the following command in the terminal.

npx create-nx-workspace

With this command you will need to enter workspace name. You can give the name as a project name.

Entering workspace name

We’ll choose React for this case.

Choosing stack

And then choose None. Because we want to create a single page application.

Choosing framework

Choose Standalone as follow.

Choosing project structure

For the bundler, choose Vite.

Choosing a bundler

And choose SASS for the stylesheet format.

Choosing stylesheet

After that choose No. Because we don’t want to use Nx Cloud for now.

Choosing to use Nx Cloud

After all of that, Nx will install require dependencies. To run the application, go to project root folder and run nx serve .

Install Nx Globally

To use additional functionality like code generators, we need to install Nx globally.

npm install --global nx@latest

Code Generator

Nx can be used to generate code templates. For example, to generate a react component we can use the following command.

nx g c component_name

If the following question show up, just press enter.

And it’ll generate a component like this.

For other templates, see here.

Done

That’s all! Now you see that with Nx you can not only easily integrate with various tools but also can be extended to a large project as a monorepo.

--

--

Ye Min Ko
Learn React

🌐 Web Developer | 👀 Self-Learner | 👨‍💻 An Introvert