Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Run builds on file changes using watch with npm scripts


    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.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: 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.

    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.

    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.

    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.