Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Babel has changed significantly.

    AngularJS with Webpack - ES6 with BabelJS


    Use the latest features of ECMAScript using BabelJS with Webpack. Simply add the right loader line in your webpack config and everything just works.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    The next thing we want to do in our application is we want to start using ES6 features today. We're going to do that with a library called Babel. There's a webpack loader for this library.

    The first thing that we'll do is we'll MPM install the Babel loader, save that as a dev dependency. And then, inside of our webpack config, we'll say module, loaders, and we'll test for all files that end in .js. For all of those, we'll apply the loader Babel.

    Now we need to restart our webpack Dev server, MPM start. In our index.js, just to make sure that everything is working, we'll change this to const. We'll save, refresh, and everything is working.

    Let's go ahead and change a couple of things to ES6. We'll say export, default, changes this to an arrow function. Everything's still working. We're good. We'll do export, default, change that to an arrow function. Everything is working.

    Just for the fun of it, we can change these to arrow functions, as well. We're going to be kind of crazy here. Yeah, that would be a bad idea, actually. Don't do that. In fact, I'll show you why.

    If you do, then this is bound to the lexical of this. So doing this is actually this being compiled down to something that looks like this and this. That's why you don't want to just go crazy using arrow functions all over the place. It's wise to only use them where it makes sense.

    It's important to know how arrow functions work, just like all JavaScript. We're going to change this back to a function, fix this back to this, and move that. Now everything is up and working. Just be aware of a couple of tricky things with ES6, but yeah, we can use ES6 features in our Angular code. Super, super easy.

    That's ES6. All that you really need to do is webpack config, loaders. Everything that ends in .js will be loaded through the Babel loader. If you want to, you can also include an exclude node modules, so that none of your dependencies will run through the Babel loader.

    We'll restart our server, refresh, and everything is still working. That's how you do ES6 with Angular.