Our goal for this section is to take the JavaScript sitting in our script tag in our index.html
(the line responsible for rendering our "Hello from React!") and move that to a JavaScript file in the src
folder, which is then bundled and injected into the HTML by Webpack.
It sounds complicated, but it’s simpler than it sounds, thanks to the magic of Webpack. Let’s get started:
- First, we need to install Webpack:
yarn add [email protected]
If you check the package.json
, you should see Webpack listed under our dependencies. For this book, I’ll be using version 3.5.4; if you run into any inexplicable problems, try specifying this version with yarn add [email protected]
:
- Now, we need to tell Webpack what to do. Let’s start by moving our React code into the
src
folder. Insidechatastrophe/src
, create a file calledindex.js
. - Then, type in the following code:
console.log(‘hello from index.js!’);
Our goal is to get this greeting to display in our browser console.
- Okay, let’s try out Webpack. In...