Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Cloud Development Deploy React .js projects


May 27, 2021 Web Cloud Development and Web Hosting Learning Guide


Table of contents


Lead

React is one of the hottest front-end frameworks of the day, and in addition to being able to deploy on your own server, Github Pages, you now have a new option to deploy using the cloud to develop static site features.

Cloud development static site hosting supports the use of cloud development SDK to invoke service-side resources such as cloud functions, cloud storage, cloud databases, etc., thereby expanding static sites to full stack sites

CloudBase is a one-stop back-end cloud service provided by Tencent Cloud for developers, which helps developers build and manage resources in a unified way, eliminates the cumbersome server construction and operation, domain name registration and filing, data interface implementation and other cumbersome processes in the process of mobile application development, so that developers can focus on the implementation of business logic, without understanding back-end logic and server operation knowledge, the development threshold is lower and more efficient.

Whether it is Tencent cloud development users, or small program cloud development users, as long as the opening of pay-per-view, you can enjoy cloud development static website hosting services.

System dependency

Before you go on, make sure you have Node installed in your PC .js the environment. If it is not installed, you can nodejs.org download the installation.

Install cloud development cli tools and React scaffolding

Once the NodeJs environment is configured, perform the following commands to install the cloud development cli tool and react scaffolding:

  1. npm install -g @cloudbase/cli
  2. npx create-react-app reactdemo

Locally initialize a React project

During the process scaffolding automatically installs the relevant dependencies required in the project, and you can see the following output after installation

Cloud Development Deploy React .js projects

Once the installation is complete, go to the project directory, start the local preview, and when successful, the project will run on the local 3000 port

  1. cd reactdemo
  2. yarn start

Cloud Development Deploy React .js projects

Open the localhost:3000 in the browser and you can see the Real interface, which indicates that the project was successfully built locally

Cloud Development Deploy React .js projects

Create a cloud development environment

Create a cloud development environment for the deployment of Real projects, which can be created from WeChat development tools, or through the Tencent Cloud Console, where cloud development can be found in products, for example, from Tencent Cloud

Cloud Development Deploy React .js projects

Go to the cloud development management console, click New Environment, or deploy using an existing environment

Cloud Development Deploy React .js projects

Create a new environment, or use an environment you've created, note that billing here requires you to choose metered billing, because only metered accounting allows you to open static sites

Cloud Development Deploy React .js projects

After opening the environment, there is an environment ID, this ID will be used later, click on the corresponding environment to enter the environment management page, click on the static website in the menu bar, open static website services

Cloud Development Deploy React .js projects

The interface shown below indicates that it has been successfully opened.

Cloud Development Deploy React .js projects

Now let's complete the deployment of the React project with a cloud-developed CLI.

Initialize the cloud development CLI

Once the cloud development environment is configured, you need to log on to the cloud development cli for deployment with cli (or, of course, upload directly from the web side)

Enter it on the command line

Cloud Development Deploy React .js projects

will jump to the cloud development console page for authorization.

Cloud Development Deploy React .js projects

After confirming the authorization, the interface in the following image appears to prove that the login was successful, and there is a small tip, that is, cloudbase can use the short-case command tcb

Cloud Development Deploy React .js projects

Package react projects and deploy them

Back in the React project catalog to perform yarn build packaging of the project, react scaffolding will package the files into the build directory by default

Cloud Development Deploy React .js projects

Once packaged, the directory that goes into the build executes the following commands for deployment, and envID needs to be replaced with its own envID

  1. cloudbase hosting:deploy -e envId

Once the deployment is complete, you're ready to preview

Cloud Development Deploy React .js projects

Online access

Go to the corresponding environment settings page, you can find the default domain name, click on the domain name, you can see that you have just deployed The act project, because the default domain name is for testing only, limit down the speed of 10KB/S.

Cloud Development Deploy React .js projects

If you need to formally provide website services to the outside world, it is best to bind a custom domain name that has been filed.

Cloud Development Deploy React .js projects

Summarize

With just a few simple steps, you can easily deploy React-generated SPA applications to cloud development without having to buy servers for deployment or the unbearable speed of deployment on Github! Save the cost of server purchases and don't act quickly?