For example, should we want to use default function parameters, along with some string interpolation. Start our server to see this in action.
If we open up the console, we're going to see that we've got an error here. One expected token. This is because at the time of recording, default function parameters are not yet supported in Chrome.
To fix this, we can use a popular project called Babel. Close that, npm install babelify. Back in our Gulp file, we'll bring that in.
Babelify is a wrapper around the Babel project, that enables it to be used as a transformer for Browserify. Before we call bundle, we simply call transform and pass that along Babelify.
This will act on every file that comes through our bundle.
We can check that's working by running our server again. Reload the browser and you can see default function parameters have now compiled correctly. Just to prove it is working, you can change that, hit "Save," and there you go.
Now we have ES6 compilation, along with a live reloading development server that should enable a really efficient workflow.
There is one more piece to this puzzle, however. If I put a debug statement here, you can see that the debugger has RAM, but it's reporting that we're in bundle.js line 14. Which is correct, according to Chrome, because it's loading this file. You can see line 14 here.
But when debugging our code, we want it to report greeting.js line 2. For that, we need source maps. We'll close down the server, go back to our Gulp file, and install Exorcist. Bringing it into our Gulp file.
Exorcist, as the name suggests, can extract a source map from a Browserify stream. The way you hook this up is, you put it before, we've transformed the Browserify stream into the vinyl source stream.
We simply pipe into it, and we pass it along wherever we want our source map to be called. We'll pull it alongside the bundle file. We'll say app.js.map.
There's one more thing we need to do to enable this. Browserify needs to know that we're in debug mode, so that it generates source maps. We'll take this out of here, and we'll first add to it debug = true. That should be enough.
Let's run our task again. This time, when the debugger runs, we are in greeting.js line 2, which is exactly where we placed the debugger statement.