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

Kent demonstrates why it’s better to export specific objects from each JavaScript module rather than have it added to the global application object. He uses the CommonJS module syntax for the exports/imports. Code for this example is located on the FEM/01.3-explicit-deps branch.
- http://slides.com/kentcdodds/webpack-deep-dive#/9/1

Get Unlimited Access Now

Kent C Dodds: Yeah, and we're actually going to skip past this one too, because I think it's also pretty straightforward. Again, this is all in the spirit of iterating slowly, like working our way into Webpack world. Because even with the way the we had it, it's still not technically explicit dependencies.

We need to like, we're acquiring this file but it's just tacking stuff onto the window dot app. So we want to instead require specific things from those different modules and then from each one of these modules we want to export specific things. Here we're using a CommonJS. I start with CommonJS because I feel like most of you are probably more familiar with CommonJS than you are with your six modules.

We'll move on to modules a little bit later. But yeah, that's the basic idea of what we're doing in this step, is making the exports explicit as well as the imports of the require statements explicit. And the cool thing about that is now if, let's say that in this helpers file or inside of app.js we require helpers.

But we somehow we don't end up using helpers in this file at all, then we know that we don't not only do not need to require it in this file, but maybe we don't need that file in our project at all. We can get rid of it. So that's having explicit dependencies solves a lot of problems.

Just kind of out of the box for us.

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