Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React without Webpack

I started to look into ReactJS. It seems that Facebook just released version 15.0.1. I looked into this framework last year, during 0.12.x version, when it was using JSXTransformer, and now it seems it went away from it.

Now it seems that almost every tutorial suggests using latest React with Webpack. Is there a way not use webpack at all? I'm trying to find a good valid example with a grunt task for React 15.x.x.

Any help would be appreciated.

like image 229
Midnight Coder Avatar asked Apr 13 '16 21:04

Midnight Coder


People also ask

Can we use React without webpack?

You don't need webpack. You don't even need JSX, you can just write React.

Can I use Babel without webpack?

When (not) to use @babel/standalone. If you're using Babel in production, you should normally not use @babel/standalone. Instead, you should use a build system running on Node. js, such as Webpack, Rollup, or Parcel, to transpile your JS ahead of time.

Can I use React without create React app?

No more introduction let's start creating React app without using create-react-app. First of all you need to have install node in your computer. To check that you can run following command in your CLI. Now let's initialise our React project using init command.

Why use webpack instead of create React app?

Configuring webpack provides complete control over the development environment, while initializing with Create React App prevents any custom configuration by default.


1 Answers

The simplest way:

<!DOCTYPE html> <html>  <head>   <meta charset="utf-8">   </head>  <body>   <div id="root"></div>    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>   <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>   <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>    <script type="text/babel">        class Hello extends React.Component{         render() {           return <p>Hello {this.props.name}</p>;         };       }        ReactDOM.render(         <Hello name='World'/>,         document.getElementById('root'),       );   </script> </body>  </html> 
like image 128
Reza Avatar answered Sep 19 '22 08:09

Reza