Instructor: Right now the entry point for this application simply logs something out to the console. Instead of doing that, I'd like this to be a React application. In order to do that, we need to install some new dependencies. In the terminal, I'm going to do an npm i, this time passing it the -S flag to save as runtime dependencies.
We're going to install React, ReactDOM, and the prop-types library. With those installed, lets go back into our app, and in the source directory, I'm going to add a new file. I'm going to call this app.js. This is going to be my top-level React component. Here, I'm going to import react from React, and I'm going to define a class component called F.
That's going to extend react.component. Then I'll expose a render method that for now is just going to return an h1 that says hello world, and then down at the bottom of the file, we're going to export default app. Then we can save the app file.
In index.js, I'm going to get rid of both lines of code, and I'm going to import react from React. I'm going to import react-dom from ReactDOM, and I'm going to import app from the relative path to our app module. I can drop down here, and I can call react-dom.render.
I'm going to render the app component into a DOM node that we'll get by ID. We'll call that app. Let's save index.js, and we're no longer using greet.js, so let's go ahead and just delete that file. Now, in the terminal, I'm going to run npm run build. We're going to see that we get some errors when we try to build this.
We're going to do that with another preset. We're going to npm i -d, because we're going to save it as a dev dependency, @babel/preset-react. With that installed, we can go into our webpack config, and where we have our Babel loader options, and we're specifying our preset env, we can add to that array.
We'll do @babel/preset-react, and we'll save our webpack config. Then back in the terminal, you can npm run build. This time, we'll see it's successful, and we get our app.bundle.js file emitted. If we go into our dist directory, and open that file up, even though it's minified, we'll see that it's far longer than it was before.
This is because React and ReactDOM are both part of this bundle now.