does react really need nodeJS on the frontend ENV?

前端 未结 2 1104
陌清茗
陌清茗 2021-01-31 04:13

I am new in react. I want to start a small hello world example of my own.

Most tutorials offer something like this:

app.js

var React = require(\'         


        
2条回答
  •  不知归路
    2021-01-31 05:07

    I think the current accepted answer is missing some key information. The answer is true - Node.js is not needed - but one of the first reasons you will encounter it is often used is that people prefer to use JSX format when writing React.

    JSX will not work in browser just like that. You can use for example babel-standalone to help browsers cope with JSX, but that means that your JSX code will be compiled again on every pageload, which isn't efficient. What's more efficient is to compile JSX while building the site, server side. Most of such tools are node based, so that's one of the reasons Node.js is often used.

    There are, of course, other reasons, JSX thing is just one of the first. There are plenty of additional javascript ecosystem related tooling that also come with Node.js. Those can be used also on, for example, java system, but it is always a bit hacky. In practice you will encounter that for different libraries and additional resources, the instructions to use tend to be given mainly for Node ecosystem, leaving others more up to the user.

提交回复
热议问题