When working on a project, you are going to need to keep clearing out your build directory that contains the code you plan to deploy, since you will be continuously updating your code. Instead of doing this manually, you can use a handy utility called rimraf and script the files you want to remove. Here’s how to use it.

  1. In your project’s directory, install rimraf using either npm or yarn:

    npm install rimraf --save-dev


    yarn add rimraf --dev

  2. In the scripts section of of your package.json file, use rimraf in the following way:

    "scripts": {
        "clean:build": "rimraf /path/to/builddir/*"
  3. Now simply use either npm or yarn to run the command to clear out your build directory:

    npm run clean:build


    yarn run clean:build