{"id":237960,"date":"2016-02-12T09:12:45","date_gmt":"2016-02-12T16:12:45","guid":{"rendered":"http:\/\/css-tricks.com\/?p=237960"},"modified":"2020-08-18T19:49:41","modified_gmt":"2020-08-19T02:49:41","slug":"why-npm-scripts","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/why-npm-scripts\/","title":{"rendered":"Why npm Scripts?"},"content":{"rendered":"\n

There has been a growing sentiment (for instance<\/a>) that using node packages directly, with the command line interfaces they provide, is a good route to take. As opposed to abstracting the functionality away behind a task runner. Partly: you use npm anyway, npm provides scripting functionality, why not just use that? But there is more to it than that. Let’s walk through the thinking, but also exactly how to accomplish many of the most important tasks in a front end development build process.<\/p>\n\n\n\n\n\n\n\n

I\u2019ve started using npm scripts<\/a> in my projects for about the last six months. Before that, I used Gulp<\/a> and before that, Grunt<\/a>. They’ve served me well and helped me perform my work faster and more efficiently by automating many of the things I used to do by hand. However, I started to feel that I was fighting the tools rather than focusing on my own code.<\/p>\n\n\n\n

Grunt, Gulp, Broccoli, Brunch and the like all require you to fit your tasks into their paradigms and configurations. Each has it\u2019s own syntaxes, quirks and gotchas that you need to learn. This adds code complexity, build complexity and makes you focus on fixing tooling rather than writing code.<\/p>\n\n\n\n

These build tools rely on plugins that wrap a core command line tool. This creates another layer of abstraction away from the core tool, which means more potential for bad things to happen.<\/p>\n\n\n

Here are three problems I\u2019ve seen multiple times:<\/h3>\n\n\n