Enough of console logs; now, let’s use Webpack to take care of some useful code:
- Delete our index2.js, and delete all code from index.js. Then, copy and paste our React code into index.js, and delete the first three script tags in the index.html.
- After doing so, you should have only one script tag in your index.html (the one for bundle.js), and your index.js should consist of this line:
ReactDOM.render(React.createElement('h1', false, 'Hello from React!'), document.getElementById('root'))
- Before we run Webpack, though, we have a problem. We deleted the script tags that required React and ReactDOM, but we still need a way to access them in our index.js.
- We can do it in the same way we required index2.js, that is, type out ...