Should npm Really Be Used as a Build Tool?

Why npm?

Let’s start with the intention behind using npm as a build tool and why many of us came to the conclusion that it might be a better choice than using existing packages:

The Remorse

Sadly, the joy didn’t last long. After people like me started converting their excitement of knowing how to simplify a certain task into a practical solution, it already started to get shitty again:

  • A lot of things are being defined multiple times (like paths and subcommands), which makes maintenance very hard.
  • You’re required to ensure that the destination directory and all sub directories exist before running an actual build task (I’ve did that using “prebuild”). If you don’t do that, many compilers/transpilers will throw an error telling you that the destination path doesn’t exist.
  • I haven’t found a way to use a single watching process and pass the changed files over to the respective build task instead of using a CLI tool like parallelshell to run multiple of those watchers in parallel.
  • These watchers also won’t care if only a single SCSS file (for example) has been changed. Instead of that, they will simply trigger a rebuild of all stylesheets because nobody tells them which ones have changed!
  • Tools like Gulp and Broccoli already include a well thought-out caching mechanism which reduces the build time to a few milliseconds (using in-memory file caches like gulp-cached even allows you to reach a overall build time of just nanoseconds). When using things like node-sass or babel directly, you’ll get a much slower speed.

Possible fixes

Technically, just running watchers concurrently and rebuilding if necessary isn’t enough for a real web application. At the same time, we also have to make sure that we’re serving the static files and the API/server code. And all of this stuff should preferably happen in a single process (to avoid monitoring multiple terminal windows, for example).

A compromise

You know what? I’m fine with looking at npm as a task manager. But what I definitely can’t recommend is using it as a build tool.





Geist of the web

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store