The full video and many others like it are all available as part of our Frontend Masters subscription.

Kent C Dodds

Kent C. Dodds works at PayPal as a full stack JavaScript engineer. He host JavaScript Air and co-hosts React30 podcasts. Kent is an Egghead.io instructor and Google Developer Expert.

Kent C Dodds

PayPal

Webpack needs an explicit entry point to be specified in the configuration file. This allows Webpack to locate all the application dependencies and include them in the packaged version of the application.

Get Unlimited Access Now

Kent C Dodds: So now that we have our output file name, like webpack keeps telling us we need, we're going to run that script again. And now it says configuration file found, but no entry configured. Okay, so we need an entry now. So let's actually go back to my slides, to talk about why entry matters.

Kent C Dodds: And then I'll give you a chance to ask a couple questions. So the entry is our main method of our app and it's responsible for requiring all the things that it needs, all of its dependencies. And then webpack will resolve those dependencies and spit out the resulting bundle, or the resulting concatenated resolves, interesting file, into the output that we specify.

I think most of this will make more sense when you can see what that result looks like. But, yeah, hopefully that's kind of like explanatory of what the purpose of this output and this entry is all about, why we use those those terms. So we'll go ahead and say entry.

And actually we're going to provide webpack with a bit of context for this entry. So all of our modules are in the source directory, so that's the context for our source files. And so, for our context, context actually needs to be an absolute path, so we're going to say const resolve = require('path').resolve.

And if you're on Node 6 then you can do this fun stuff.
Kent C Dodds: So then we're going to use resolve to resolve directly to source. Let me just get rid of that, sorry. So if you are following along, that's hopefully helpful, and our entry inside the source directory, in that context, is this bootstrap.js file.

So I'll say bootstrap.js
Kent C Dodds: Awesome, I'm almost to the point where I'll let you loose on this. Whoops, that needs to be a relative path, sorry.
Speaker 2: There's a question, any reason that they're not getting webpack errors in their terminal? A couple of people.
Kent C Dodds: Yeah, if you aren't seeing the webpack errors that we were seeing earlier then that's probably a problem.

This is one of those weird cases, where errors indicate good things. So yeah if you're not just keep following along, and hopefully magically it works.
Speaker 3: What was the error supposed to look like again?
Kent C Dodds: The errors were the ones that were like, you need to have the output file name.

And then it says, you need to have an entry configured. And once you resolve those things, you probably won't get this one unless you made the same mistake I did where this wasn't relative. You'll get that one if it was not relative. But once you get it working this is what you should see.

You'll see the time that it took, you'll see the assets that were created. And the exciting bit is you'll see this new file in your file system that's breaking all your linting errors or linting rules, but it is your bundle. So I'll quickly explain what this bundle is and then I'm going to stop and let everybody work on it, and I'll be available to answer some questions.

So the bundle here is a bunch of code that you didn't write, remember our entry is just this file right here. This file has no explicit dependencies, no require statements, or any kind of imports of any kind. And so you might be wondering so what on Earth is all of this code?

Well, webpack ships with a runtime. So webpack is going to turn all of your require statements, or your import statements, into what's called a webpack require to resolve all the modules at runtime. And it needs a runtime to accomplish that task, so that's what all of this code is.

And then finally we get to our little module right here. And it looks exactly as it was, it just said, okay, take that and just plop it in. It will change some things, if it finds import statements and things it'll change those to work with the webpack runtime.

But other than it's pretty much just our code, we're not transpiling or anything at this point. So one interesting thing about this is, remember, we have it in an immediately invoked function expression. We don't need to do that anymore because it's already in this closure. So already we can get rid of writing some boilerplate code, which is cool.

We'll do that a little bit later. And, yeah, that's basically the whole idea. Sorry, one other thing that I want to do and then I'll let you loose. Now that we have this bundling we can change this bootstrap.js to bundle.js. And if we run npn start with that change we can refresh this and the app still works, you should see view set in the console and all of your to dos.

Ready to take your code to the next level?

Intense courses with world-class teachers and unlimited access to our growing library of videos for the great price of $39 per month.

Get Unlimited Access Now