Introduction to Using NPM as a Build Tool

Nader Dabit
JavaScript Training
11 min readOct 28, 2015

--

To learn more about this topic, I highly recommend this Pluralsight tutorial for a more detailed overview.

npm is gaining more and more steam as a replacement for other build tools such as Gulp, Grunt, Bower, and others. While the previously mentioned are great tools, node provides a great way to implement build processes with only npm and your package.json file. Here, we will go into an introduction to this process as well as a few key things to know about if you are looking to learn about using NPM as a build tool.

Using npm as a build tool is all about working in the package.json file and creating custom scripts in the scripts object of file, so that is where we will spend most of our time.

Why use NPM vs the others mentioned above?

  1. NPM is already part of your process when using node.
  2. Any command that you are already running at the command prompt can be moved into your package.json file and used there.
  3. NPM ecosystem is huge, and very active.
  4. Having your build process in your package.json file is much less overhead. You only have to keep this file updated as opposed to multiple configuration files for your build process.

1. Getting Started

  1. Create a new clean directory, then open your terminal into that directory.
  2. Run the following command:
npm init

--

--

Nader Dabit
JavaScript Training

Full Stack Product Engineer, Author, Teacher, Director of Developer Relations at Avara