Because webpack needs to be used in react, and webpack relies on nodejs; webpack is a module packager, which relies on nodejs when performing packaging and compression. Webpack cannot be used without nodejs, so react needs to use nodejs. .
The operating environment of this tutorial: Windows 10 system, react17.0.1 version, Dell G3 computer.
To learn React, you need to install nodejs. The main reason is not that React depends on nodejs, but that webpack depends on nodejs.
Webpack relies on nodejs when performing packaging and compression. Webpack cannot be used without nodejs. Just like if you want to use a light, you must first have current, and current requires an engine to generate electricity. You can't use current directly just because you say I don't want an engine.
Introduction to Commonly Used Tools
1、nodejs
: Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. how to understand? First of all, node.js is a JavaScript runtime environment. Generally, the JavaScript we know runs in the browser. So you can understand why it is based on Chrome's V8 JavaScript engine. With nodejs, you can abstract JavaScript public components and deploy them separately on nodejs to provide public services. The front-end possibilities are now more imaginative.
2,npm
: (node package manager)node package manager, mainly manages node package installation, uninstallation, updating, viewing, searching and publishing. Free developers from tedious package management work (versions, dependencies). Nodejs has integrated npm, so npm is also installed when installing nodejs.
3,nvm
: node version manager, which can be used to easily install and maintain multiple Node versions on the machine. So why do you need multiple versions? There are many scenarios. For example, you may be working on two projects at the same time, and the node versions used by different projects are different; or you may want to use a newer version to do some experiments. In this case, it would be troublesome to install and maintain multiple versions of node without NVM. This is the value of nvm.
4,webpack
: webpack is a module bundler (webpack is a module bundler). It is to analyze the structure of your current project, package things that the browser used in the project cannot understand (SCSS, jade, Typescript, etc.) in an appropriate way and translate them into css and js that the browser can understand. In webpack everything is a module (images and CSS too).
Recommended learning: "react video tutorial"
The above is the detailed content of Why use node in react. For more information, please follow other related articles on the PHP Chinese website!