Autoplay

    Run builds on file changes using watch with npm scripts

    Trevor MillerTrevor Miller

    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.

    npmnpm
    Code

    Code

    Become a Member to view code

    You must be a 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
    Transcript

    Transcript

    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.

    Discuss

    Discuss