Introduction to npm as a Build Tool

The Node Package Manager (npm) and the package.json file in combination makes a great option for build automation. Using npm and package.json is simpler and has no extra dependencies such as Gulp and Grunt for example. It's easy to get started by moving your existing commands into the package.json and you can utilize the entire Node package library in your script.
Course info
Rating
(200)
Level
Beginner
Updated
Oct 20, 2015
Duration
1h 37m
Table of contents
Description
Course info
Rating
(200)
Level
Beginner
Updated
Oct 20, 2015
Duration
1h 37m
Description

Why should I even care about this when there's an abundance of great tools already? npm is baked into your process already. No build tools are needed and any command you run at the command prompt today can be moved into your package.json with one line of code. The Node package library, that you most likely are using anyway, is vast and contains just about anything you need for your automation. Keeping it in npm and package.json means that everyone can use it. No additional configuration is needed. Just npm install and then use the scripts. You now only have one place to keep updated.

About the author
About the author

Get agile to work in practice - is my motto. This had led me to take interest in all kinds of things: Lean, TDD, Kanban, Specification by example, Node, Continuous Deliver, Nancy and Koa.

More from the author
io.js and Node.js Next: Getting Started
Intermediate
42m
4 Jun 2015
Introduction to Koa Javascript
Intermediate
2h 3m
12 Dec 2014
Section Introduction Transcripts
Section Introduction Transcripts

Pre and Post Hooks
As we start to use more and more scripts, we will soon find the need of structuring the execution of our scripts a bit. Luckily, npm has a few tools built in to do so. In this module, we will specifically check in on the pre and post hooks that help us to organize our scripts a bit.

Scripts for Development and Test
Starting from this module and a couple of modules forward, we will change gears a little bit. So far, we learned about the basics and syntax and functionality of scripting with npm. We will now use those acquired skills to support us in different stages of the development cycle. In this module, we will create a few scripts that can be useful when we develop and test our application. I'll make sure to sneak in some tips and tricks in the progress, too.

Scripts for Development: Watching
As JavaScript is a dynamic language, there are a number of checks that we want to have run continuously to make sure that we can proceed our development with confidence. For example, our linting and testing are two such things for the server-side. On the client, there's an additional layer of complexity. When we change a parameter in a. less file, for example, it has to be compiled to a css file, and then the browser has to be reloaded for us to see how that change looks. Let's in this module take a look on how we can continuously watch our changes and have scripts executed as the consequences of those changes, leaving us to focus on our code rather than to start scripts.

Versioning, Pushing, and Deploying
The last two modules focused on developing and testing, but an application that is not used by users is truly useless, I'm sure everyone agrees with. Therefore, in this module, we will take a look at writing a few scripts to support us in versioning, pushing to our repository, and deploying to our platform of choice. As we said, our scripts node is getting pretty long in the package. json by now. Remember that we can get a quick log of the available commands with npm run. This module focuses on the individual scripts, and in the next, we will put many things that we learned so far during the course together into a big deploy to production script. So, if you're missing a step here, like compiling, testing, bundling, before we're pushing to production, don't worry, that's in the next module. Let's hop to it.

Deploy Script and Additional Tricks
Okay, let's wrap this course in one big deploy to production script. Here is what we want it to do. First, lint, compile, and test our server-side JavaScript. Secondly, bundle and minify our client-side JavaScript. Compile our less code to CSS. Bump the version number to the next patch number, push to a remote GitHub repository, deploy to Heroku, Well, let's open it to verify that our application works, too, just for good measure. All of the parts are written. We're just going to put it all together. As it turns out, this will be pretty easy.

npm as Build Script Summary
This course set out with the assumption that we could npm and the package. json file as our build tool. This is the way that Node and npm themselves are built, and take away the dependencies on third-party products, such as Gulp and Grunt and all of their packages. To our help, we have the entire plethora of packages and tools that npm offers, the largest Open Source library in the world. Through the course, we have created a monstrously long package. json file with a lot of example scripts and ways that you can use the scripting capabilities of npm to your advantage.