Getting Started with NPM Scripts – Babel

Previously we used Gulp a few time to automate some build steps. Lets take a look at how we can accomplish some of the same things with functionality build in the node ecosystem by using npm-scripts.

Getting Started

To begin we will need to have Node.js installed and npm conveniently if you install Node.js from the installer on the website npm will be installed as well. to make sure you have the latest version of npm use the following command:

Update npm

npm install npm -g

If you are on a Mac or Linux you may need to use the sudo command.

Now lets create a new folder for our little project and set up a package.json. Let’s run npm init with the following responses:

Now that we have that out of they way we can move on to the meat and potatoes of our topic.

Setting Up Babel

To add Babel we will need to run npm install --save-dev babel-cli babel-preset-es2015.

If you read the last time we set up Babel you may remember we need to add a preset for doing ES6 => ES5 so that things actually get transpiled to ES5 so we just added the preset at the same time as the babel-cli

That should add a new section to your package.json that called devDependencies that looks like the following:

Conclusion

We are just getting started but one thing you may have noticed is that we didn’t need to install any npm modules globally so we wont have to worry about what version anything is we used on different projects. This this has been silly so far and you will never try anything besides your beloved ${readersFavoriteJavaScriptBuildTool}? I would love to hear about it, leave a comment below or send an email to me at brett@wipdeveloper.com.