Search code examples
node.jsnpmyarnpkgpackage.json

Calling one script from another with Yarn


Below is an example how to run a script from another with npm in package.json.

What's the equivalent with yarn?

{
  "name": "npm-scripts-example",
  "version": "1.0.0",
  "description": "npm scripts example",
  "scripts": {
    "clean": "rimraf ./dist && mkdir dist",
    "prebuild": "npm run clean",

  }
}

Solution

  • You could do

    {
      "name": "npm-scripts-example",
      "version": "1.0.0",
      "description": "npm scripts example",
      "scripts": {
        "clean": "rimraf ./dist && mkdir dist",
        "prebuild": "yarn run clean",
    
      }
    }
    

    And then the command yarn run prebuildshould work. Also you could just do yarn run clean.

    Documentation of the run cli : https://yarnpkg.com/lang/en/docs/cli/run/