Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Require with React in a web page without node [closed]

I know this might be a silly question to some of you, but I am beginner in React, and I wish to create a really simple application. I found a sample in which every component is saved in a separate js file, which looks very good for modularity and re-usage.

The only thing I need to take care of now is using export/require. However, I don't need to be dependent on nodejs. I just need a simple html/js application that can run on any cheap web server.

I read somewhere that I can use "Browserify", but after looking at it, it seems like a node library.

Is there any library that I can use from a web page (via cdn for example) that allow me to use require? If not, does that mean I can not separate react components in different files?

like image 293
Lamar Avatar asked Jan 17 '17 08:01

Lamar


People also ask

Can React be used without node?

You don't need Node to run a React project. You don't even need a browser. React gives you a language to describe a user interface (UI). That interface could be the controls in your car, a modern fridge screen, or your microwave buttons.

Can React use require?

While you can still use require() and module. exports , we encourage you to use import and export instead.

Can you use React without backend?

Stage 1: No Backendjs or Gatsby, you don't need a backend. Instead, you could simply write your blog posts as markdown files, which are stored and tracked (using Git) within a project folder.

Do you need to know node before React?

So before moving to React, you should have a solid understanding NPM (Node package manager) registry and how to install packages using NPM. NPM registry keeps track of the file that has been submitted.


1 Answers

However, I don't need to be dependent on nodejs.

Use NodeJS. It is how React applications are designed to be built.

I just need a simple html/js application that can run on any cheap web server

NodeJS is only required at build time. You run it on your development workstation. The output is static files that you can upload to any webserver.

(NB: React applications are often designed to make HTTP requests to get dynamic data. Some tutorials cover using Node to build a server to listen for and make responses to those requests. Make sure you don't conflate the program to transpile the React application to ES5 (which runs at build time) with the program to run a webserver (at runtime) even if both are written using Node).

like image 168
Quentin Avatar answered Sep 28 '22 02:09

Quentin