This course has been updated! We now recommend you take the Complete Intro to React, v8 course.
Transcript from the "NPM Scripts" Lesson
>> Brian Holt: We're gonna talk about NPM Scripts for just a second. A lot of times when you're having build tools or testing or linting or any one of these, like we have to run these long commands to get them to work. It's really tough to remember those off the top of your head, at least it is for me.
[00:00:16] Like when we run our testing suite at Netflix, you have to run it with ten different flags to get it to work just the way that you're expecting it to work, and that's really hard to remember. So NPM includes this thing called scripts that you can put in your package.json.
[00:00:30] That basically says like, here's a short list of commands that you don't have to remember, you just have to remember what it's called and I'll run this for you. With some other extra magic. But that's a good basic description of it. So, in our particular case, we want it to say, every time we say, hey, run our linter.
>> Brian Holt: Then I want you to just run standard. And you can basically think of whatever in the second part is just going to be piped into bash for you, or whatever your shell is.
>> Brian Holt: Okay? So if I save that.
>> Brian Holt: And I go to my command line, and I say npm run lint.
[00:01:20] Now this is just gonna say, hey I'm gonna just run standard cuz that's what you told me to do when you say run lint. So this is just a really easy thing to remember your particular projects, nuances. Standard's not super useful because obviously, it's easier to remember standard.
[00:01:38] But as we get more and more complicated build commands, this will be very useful very quickly.
>> Brian Holt: So my kind of caveat I'll give you here. A lot of people try to replace Grunt and Gulp with their NPM scripts. I don't necessarily suggest that.
>> Brian Holt: If you have a big, complicated build process with Gulp or with Grunt or anything like that, trying to replicate that inside of NPM scripts is kind of a pain.
[00:02:09] Our builds are gonna be fairly simple. So we can get away with getting NPM scripts. But as soon as you find yourself like rebuilding Grunt using Bash, you've gone too far. [LAUGH] Like, build a Grunt file or a Gulp file or whatever build process you find that you like.
[00:02:26] And then go from there. But until that point, NPM scripts works. But there is a place for Gulp and Grunt these days, those are still useful tools.