Run builds on file changes using watch with npm scripts

Trevor Miller
InstructorTrevor Miller

Share this video with your friends

Send Tweet
Published 6 years ago
Updated 4 years ago

We can set up a file watcher to compile automatically while we develop. In this lesson we wire up a new dev script to run the build script when source files change.

Instructor: [00:02] Let's type npm-install-watch and then let's save this to our development dependencies. Now, if we open up our package.json and look at the development dependencies, we have this new watch package available.

[00:15] If we go to our scripts, now we can add a new dev script which runs our watch binary and runs the command npm-run-build whenever the source directory changes.

[00:28] Now, in two separate terminal panes, we should be able to run npm-run-dev in one of them. In the other, we should be able to go into our source directory, make a change, and have it automatically change in our build directory.

[00:42] Let's change this world to the universe, make a save, and our build command was just run. If we go look at our build folder, we can see that hello-world was changed to hello-universe.